From 1bd1a9cba3946a4ffd66273cb78af30b87bca327 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 25 Dec 2023 06:03:56 +0100 Subject: [PATCH] Fix https://github.com/firefly-iii/firefly-iii/issues/8291 AND fix issue with non-strict rule triggers AND fix behaviour of actions --- .ci/php-cs-fixer/composer.lock | 13 ++++++------- .../Collector/Extensions/MetaCollection.php | 4 +++- app/TransactionRules/Engine/SearchRuleEngine.php | 13 +++++++++++-- public/v1/js/ff/rules/create-edit.js | 16 +++++++++++++++- resources/views/rules/partials/trigger.twig | 2 +- 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/.ci/php-cs-fixer/composer.lock b/.ci/php-cs-fixer/composer.lock index d2d8fc2c9d..c27d109b34 100644 --- a/.ci/php-cs-fixer/composer.lock +++ b/.ci/php-cs-fixer/composer.lock @@ -226,16 +226,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.41.1", + "version": "v3.42.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "8b6ae8dcbaf23f09680643ab832a4a3a260265f6" + "reference": "632ef1be3447a9b890bef06147475facee535d0f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/8b6ae8dcbaf23f09680643ab832a4a3a260265f6", - "reference": "8b6ae8dcbaf23f09680643ab832a4a3a260265f6", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/632ef1be3447a9b890bef06147475facee535d0f", + "reference": "632ef1be3447a9b890bef06147475facee535d0f", "shasum": "" }, "require": { @@ -266,7 +266,6 @@ "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.4", "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.4", "phpunit/phpunit": "^9.6", - "symfony/phpunit-bridge": "^6.3.8 || ^7.0", "symfony/yaml": "^5.4 || ^6.0 || ^7.0" }, "suggest": { @@ -305,7 +304,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.41.1" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.42.0" }, "funding": [ { @@ -313,7 +312,7 @@ "type": "github" } ], - "time": "2023-12-10T19:59:27+00:00" + "time": "2023-12-24T14:38:51+00:00" }, { "name": "psr/container", diff --git a/app/Helpers/Collector/Extensions/MetaCollection.php b/app/Helpers/Collector/Extensions/MetaCollection.php index 4f06a6049a..e082a635cf 100644 --- a/app/Helpers/Collector/Extensions/MetaCollection.php +++ b/app/Helpers/Collector/Extensions/MetaCollection.php @@ -680,10 +680,11 @@ trait MetaCollection // this method adds a "postFilter" to the collector. $list = $tags->pluck('tag')->toArray(); + $list = array_map('strtolower', $list); $filter = static function (array $object) use ($list): bool { Log::debug(sprintf('Now in setTags(%s) filter', implode(', ', $list))); $expectedTagCount = count($list); - $foundTagCount = 0; + $foundTagCount = 0; foreach ($object['transactions'] as $transaction) { $transactionTagCount = count($transaction['tags']); app('log')->debug(sprintf('Transaction has %d tag(s)', $transactionTagCount)); @@ -719,6 +720,7 @@ trait MetaCollection // this method adds a "postFilter" to the collector. $list = $tags->pluck('tag')->toArray(); + $list = array_map('strtolower', $list); $filter = static function (array $object) use ($list): bool { Log::debug(sprintf('Now in setWithoutSpecificTags(%s) filter', implode(', ', $list))); foreach ($object['transactions'] as $transaction) { diff --git a/app/TransactionRules/Engine/SearchRuleEngine.php b/app/TransactionRules/Engine/SearchRuleEngine.php index 866fa9f3e3..edfb5e5776 100644 --- a/app/TransactionRules/Engine/SearchRuleEngine.php +++ b/app/TransactionRules/Engine/SearchRuleEngine.php @@ -325,6 +325,12 @@ class SearchRuleEngine implements RuleEngineInterface $total = $total->merge($collection); app('log')->debug(sprintf('Total collection is now %d transactions', $total->count())); ++$count; + // if trigger says stop processing, do so. + if($ruleTrigger->stop_processing && $collection->count() > 0) { + app('log')->debug('The trigger says to stop processing, so stop processing other triggers.'); + + break; + } } app('log')->debug(sprintf('Total collection is now %d transactions', $total->count())); app('log')->debug(sprintf('Done running %d trigger(s)', $count)); @@ -465,11 +471,14 @@ class SearchRuleEngine implements RuleEngineInterface } // pick up from the action if it actually acted or not: - if ($ruleAction->stop_processing) { - app('log')->debug(sprintf('Rule action "%s" asks to break, so break!', $ruleAction->action_type)); + if ($ruleAction->stop_processing && true === $result) { + app('log')->debug(sprintf('Rule action "%s" reports changes AND asks to break, so break!', $ruleAction->action_type)); return true; } + if ($ruleAction->stop_processing && false === $result) { + app('log')->debug(sprintf('Rule action "%s" reports NO changes AND asks to break, but we wont break!', $ruleAction->action_type)); + } return false; } diff --git a/public/v1/js/ff/rules/create-edit.js b/public/v1/js/ff/rules/create-edit.js index 11e020a57b..dc9d6c558d 100644 --- a/public/v1/js/ff/rules/create-edit.js +++ b/public/v1/js/ff/rules/create-edit.js @@ -41,14 +41,26 @@ $(function () { console.log('action count is zero, add action.'); addNewAction(); } - + makeRuleStrict(); $('.add_rule_trigger').click(addNewTrigger); $('.add_rule_action').click(addNewAction); + $('#ffInput_strict').change(makeRuleStrict); $('.test_rule_triggers').click(testRuleTriggers); $('.remove-trigger').unbind('click').click(removeTrigger); $('.remove-action').unbind('click').click(removeAction); }); +function makeRuleStrict() { + var value = $('#ffInput_strict').is(':checked'); + if(value) { + // is checked, stop processing triggers is not relevant. + $('.trigger-stop-processing').prop('checked', false); + $('.trigger-stop-processing').prop('disabled', true); + return; + } + $('.trigger-stop-processing').prop('disabled', false); +} + /** * This method triggers when a new trigger must be added to the form. */ @@ -181,6 +193,7 @@ function onAddNewAction() { console.log('Trigger updateActionInput() for select ' + select); updateActionInput(select); }); + makeRuleStrict(); } /** @@ -207,6 +220,7 @@ function onAddNewTrigger() { console.log('Trigger updateTriggerInput() for select ' + select); updateTriggerInput(select); }); + makeRuleStrict(); } /** diff --git a/resources/views/rules/partials/trigger.twig b/resources/views/rules/partials/trigger.twig index 3f6e26b929..52fcb3f251 100644 --- a/resources/views/rules/partials/trigger.twig +++ b/resources/views/rules/partials/trigger.twig @@ -34,7 +34,7 @@