diff --git a/app/Api/V1/Controllers/Models/Rule/TriggerController.php b/app/Api/V1/Controllers/Models/Rule/TriggerController.php index 0f4d77afe2..cfe33ca6fe 100644 --- a/app/Api/V1/Controllers/Models/Rule/TriggerController.php +++ b/app/Api/V1/Controllers/Models/Rule/TriggerController.php @@ -54,7 +54,7 @@ final class TriggerController extends Controller parent::__construct(); $this->middleware(function ($request, $next) { /** @var User $user */ - $user = auth()->user(); + $user = auth()->user(); $this->ruleRepository = app(RuleRepositoryInterface::class); $this->ruleRepository->setUser($user); @@ -69,10 +69,10 @@ final class TriggerController extends Controller */ public function testRule(TestRequest $request, Rule $rule): JsonResponse { - $parameters = $request->getTestParameters(); + $parameters = $request->getTestParameters(); /** @var RuleEngineInterface $ruleEngine */ - $ruleEngine = app(RuleEngineInterface::class); + $ruleEngine = app(RuleEngineInterface::class); $ruleEngine->setRules(new Collection()->push($rule)); // overrule the rule(s) if necessary. @@ -94,21 +94,21 @@ final class TriggerController extends Controller $count = $transactions->count(); // enrich - $enrichment = new TransactionGroupEnrichment(); + $enrichment = new TransactionGroupEnrichment(); $enrichment->setUser($rule->user); $transactions = $enrichment->enrich($transactions); - $paginator = new LengthAwarePaginator($transactions, $count, 31_337, $this->parameters->get('page')); - $paginator->setPath(route('api.v1.rules.test', [$rule->id]).$this->buildParams()); + $paginator = new LengthAwarePaginator($transactions, $count, 31_337, $this->parameters->get('page')); + $paginator->setPath(route('api.v1.rules.test', [$rule->id]) . $this->buildParams()); // resulting list is presented as JSON thing. - $manager = $this->getManager(); + $manager = $this->getManager(); /** @var TransactionGroupTransformer $transformer */ - $transformer = app(TransactionGroupTransformer::class); + $transformer = app(TransactionGroupTransformer::class); $transformer->setParameters($this->parameters); - $resource = new FractalCollection($transactions, $transformer, 'transactions'); + $resource = new FractalCollection($transactions, $transformer, 'transactions'); $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); diff --git a/app/Events/Model/TransactionGroup/TransactionGroupEventObjects.php b/app/Events/Model/TransactionGroup/TransactionGroupEventObjects.php index 51ea18da68..f6041699a4 100644 --- a/app/Events/Model/TransactionGroup/TransactionGroupEventObjects.php +++ b/app/Events/Model/TransactionGroup/TransactionGroupEventObjects.php @@ -46,12 +46,36 @@ class TransactionGroupEventObjects return $object; } + public function collectFromCollection(Collection $collection): void + { + Log::debug('Will now collect info from collection.'); + /** @var TransactionGroup|null $object */ + foreach ($collection as $object) { + if ($object instanceof TransactionGroup) { + Log::debug(sprintf('Added group #%d', $object->id)); + $this->appendFromTransactionGroup($object); + } + if (!($object instanceof TransactionGroup)) { + if (is_array($object) && array_key_exists('id', $object)) { + // FIXME technically speaking not sure of this is the user's transaction group. + $group = TransactionGroup::find((int)$object['id']); + if (null !== $group) { + Log::debug(sprintf('Added group #%d', $group->id)); + $this->appendFromTransactionGroup($group); + } + } + } + } + } + public function appendFromTransactionGroup(TransactionGroup $transactionGroup): void { + Log::debug(sprintf('Appended transaction group #%d', $transactionGroup->id)); $this->transactionGroups->push($transactionGroup); /** @var TransactionJournal $journal */ foreach ($transactionGroup->transactionJournals as $journal) { + Log::debug(sprintf('Appended transaction journal #%d', $journal->id)); $this->transactionJournals->push($journal); $this->budgets = $this->budgets->merge($journal->budgets); $this->categories = $this->categories->merge($journal->categories); @@ -59,6 +83,7 @@ class TransactionGroupEventObjects /** @var Transaction $transaction */ foreach ($journal->transactions as $transaction) { + Log::debug(sprintf('Appended account #%d', $transaction->account->id)); $this->accounts->push($transaction->account); } } diff --git a/app/TransactionRules/Engine/SearchRuleEngine.php b/app/TransactionRules/Engine/SearchRuleEngine.php index 4e4217e8d2..cfa711a62c 100644 --- a/app/TransactionRules/Engine/SearchRuleEngine.php +++ b/app/TransactionRules/Engine/SearchRuleEngine.php @@ -25,6 +25,9 @@ declare(strict_types=1); namespace FireflyIII\TransactionRules\Engine; use Carbon\Carbon; +use FireflyIII\Events\Model\TransactionGroup\TransactionGroupEventFlags; +use FireflyIII\Events\Model\TransactionGroup\TransactionGroupEventObjects; +use FireflyIII\Events\Model\TransactionGroup\UpdatedSingleTransactionGroup; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Note; use FireflyIII\Models\Rule; @@ -399,9 +402,17 @@ class SearchRuleEngine implements RuleEngineInterface private function fireNonStrictRule(Rule $rule): bool { Log::debug(sprintf('SearchRuleEngine::fireNonStrictRule(%d)!', $rule->id)); + $flags = new TransactionGroupEventFlags(); + $flags->applyRules = false; + $flags->fireWebhooks = false; + $objects = new TransactionGroupEventObjects(); $collection = $this->findNonStrictRule($rule); + $objects->collectFromCollection($collection); $this->processResults($rule, $collection); + // collect from collection, again! + $objects->collectFromCollection($collection); + event(new UpdatedSingleTransactionGroup($flags, $objects)); Log::debug(sprintf('SearchRuleEngine:: Done processing non-strict rule #%d', $rule->id)); return $collection->count() > 0; @@ -438,10 +449,23 @@ class SearchRuleEngine implements RuleEngineInterface private function fireStrictRule(Rule $rule): bool { Log::debug(sprintf('SearchRuleEngine::fireStrictRule(%d)!', $rule->id)); + + $flags = new TransactionGroupEventFlags(); + $flags->applyRules = false; + $flags->fireWebhooks = false; + $objects = new TransactionGroupEventObjects(); $collection = $this->findStrictRule($rule); + $objects->collectFromCollection($collection); $this->processResults($rule, $collection); + // collect from collection, again! + $objects->collectFromCollection($collection); + + // fire event for changed groups. + event(new UpdatedSingleTransactionGroup($flags, $objects)); + + $result = $collection->count() > 0; if ($result) { Log::debug(sprintf('SearchRuleEngine:: Done. Rule #%d was triggered (on %d transaction(s)).', $rule->id, $collection->count())); diff --git a/config/passport.php b/config/passport.php index 153a655f57..011c210b2a 100644 --- a/config/passport.php +++ b/config/passport.php @@ -1,38 +1,17 @@ . - */ - -declare(strict_types=1); - return [ + /* - |-------------------------------------------------------------------------- - | Passport Guard - |-------------------------------------------------------------------------- - | - | Here you may specify which authentication guard Passport will use when - | authenticating users. This value should correspond with one of your - | guards that is already present in your "auth" configuration file. - | - */ +|-------------------------------------------------------------------------- +| Passport Guard +|-------------------------------------------------------------------------- +| +| Here you may specify which authentication guard Passport will use when +| authenticating users. This value should correspond with one of your +| guards that is already present in your "auth" configuration file. +| +*/ 'guard' => envDefaultWhenEmpty(env('AUTHENTICATION_GUARD'), 'web'), @@ -51,32 +30,12 @@ return [ 'public_key' => env('PASSPORT_PUBLIC_KEY'), - /* - |-------------------------------------------------------------------------- - | Client UUIDs - |-------------------------------------------------------------------------- - | - | By default, Passport uses auto-incrementing primary keys when assigning - | IDs to clients. However, if Passport is installed using the provided - | --uuids switch, this will be set to "true" and UUIDs will be used. - | - */ - - 'client_uuids' => false, - - /* - |-------------------------------------------------------------------------- - | Personal Access Client - |-------------------------------------------------------------------------- - | - | If you enable client hashing, you should set the personal access client - | ID and unhashed secret within your environment file. The values will - | get used while issuing fresh personal access tokens to your users. - | - */ - 'personal_access_client' => [ 'id' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_ID'), 'secret' => env('PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET'), ], + + 'middleware' => [], + 'connection' => env('PASSPORT_CONNECTION'), + ]; diff --git a/resources/views/list/groups.twig b/resources/views/list/groups.twig index 9977af98b6..6c6d1da838 100644 --- a/resources/views/list/groups.twig +++ b/resources/views/list/groups.twig @@ -32,9 +32,9 @@   {{ trans('list.description') }} - {{ trans('list.amount') }} + {{ trans('list.amount') }} {% if fireflyiiiconfig('use_running_balance', true) %} - {{ trans('list.running_balance') }} + {{ trans('list.running_balance') }} {% endif %} {{ trans('list.date') }} {{ trans('list.source_account') }}