From e7bb4a8ec6b69a6b1f2fab83bf12f49798465a08 Mon Sep 17 00:00:00 2001 From: Robert Horlings Date: Wed, 17 Feb 2016 10:17:16 +0100 Subject: [PATCH 1/9] Implemented option to specify pagesize when retrieving journals --- app/Repositories/Journal/JournalRepository.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 6184ff9d47..9de4c9785b 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -92,9 +92,9 @@ class JournalRepository implements JournalRepositoryInterface * * @return LengthAwarePaginator */ - public function getJournalsOfTypes(array $types, int $offset, int $page) + public function getJournalsOfTypes(array $types, int $offset, int $page, int $pagesize = 50) { - $set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset) + $set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take($pagesize)->offset($offset) ->orderBy('date', 'DESC') ->orderBy('order', 'ASC') ->orderBy('id', 'DESC') @@ -102,7 +102,7 @@ class JournalRepository implements JournalRepositoryInterface ['transaction_journals.*'] ); $count = Auth::user()->transactionJournals()->transactionTypes($types)->count(); - $journals = new LengthAwarePaginator($set, $count, 50, $page); + $journals = new LengthAwarePaginator($set, $count, $pagesize, $page); return $journals; } From b9620b3a2127d67741fb53118eff81c6a0fe80eb Mon Sep 17 00:00:00 2001 From: Robert Horlings Date: Wed, 17 Feb 2016 10:24:40 +0100 Subject: [PATCH 2/9] Refactored method to check whether a transaction is triggered by a list of triggers --- app/Rules/Processor.php | 43 ++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/app/Rules/Processor.php b/app/Rules/Processor.php index c8c3a3b3cf..1b1d78341b 100644 --- a/app/Rules/Processor.php +++ b/app/Rules/Processor.php @@ -92,6 +92,22 @@ class Processor } + /** + * Checks whether the current transaction is triggered by the current rule + * @return boolean + */ + public function isTriggered() { + return $this->triggered(); + } + + /** + * Checks whether the current transaction is triggered by the list of given triggers + * @return boolean + */ + public function isTriggeredBy(array $triggers) { + return $this->triggeredBy($triggers); + } + /** * @return bool */ @@ -121,21 +137,22 @@ class Processor } /** + * Method to check whether the current transaction would be triggered + * by the given list of triggers * @return bool - */ - protected function triggered() - { + */ + protected function triggeredBy($triggers) { $foundTriggers = 0; $hitTriggers = 0; /** @var RuleTrigger $trigger */ - foreach ($this->rule->ruleTriggers()->orderBy('order', 'ASC')->get() as $trigger) { + foreach ($triggers as $trigger) { $foundTriggers++; $type = $trigger->trigger_type; - + if (!isset($this->triggerTypes[$type])) { abort(500, 'No such trigger exists ("' . $type . '").'); } - + $class = $this->triggerTypes[$type]; Log::debug('Trigger #' . $trigger->id . ' for rule #' . $trigger->rule_id . ' (' . $type . ')'); if (!class_exists($class)) { @@ -149,12 +166,20 @@ class Processor if ($trigger->stop_processing) { break; } - + } Log::debug('Total: ' . $foundTriggers . ' found triggers. ' . $hitTriggers . ' triggers were hit.'); - + return ($hitTriggers == $foundTriggers); - + + } + /** + * Checks whether the current transaction is triggered by the current rule + * @return bool + */ + protected function triggered() + { + return $this->triggeredBy($this->rule->ruleTriggers()->orderBy('order', 'ASC')->get()); } From c8c69f1a6669579bccb2dd5c4f8f928c5a482b67 Mon Sep 17 00:00:00 2001 From: Robert Horlings Date: Wed, 17 Feb 2016 12:05:41 +0100 Subject: [PATCH 3/9] Implemented controller method and helper object to find matching transactions --- app/Http/Controllers/RuleController.php | 69 ++++++++ app/Http/routes.php | 3 +- app/Rules/TransactionMatcher.php | 148 ++++++++++++++++++ .../rules/partials/test-trigger-modal.twig | 22 +++ resources/views/rules/rule/create.twig | 3 + resources/views/rules/rule/edit.twig | 3 + 6 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 app/Rules/TransactionMatcher.php create mode 100644 resources/views/rules/partials/test-trigger-modal.twig diff --git a/app/Http/Controllers/RuleController.php b/app/Http/Controllers/RuleController.php index b8feba57e4..3b15ca91f9 100644 --- a/app/Http/Controllers/RuleController.php +++ b/app/Http/Controllers/RuleController.php @@ -25,6 +25,7 @@ use Response; use Session; use URL; use View; +use FireflyIII\Rules\TransactionMatcher; /** * Class RuleController @@ -333,6 +334,74 @@ class RuleController extends Controller return redirect(session('rules.rule.edit.url')); } + /** + * @return \Illuminate\View\View + */ + public function testTriggers() { + // Create a list of triggers + $triggers = $this->getTriggerList(); + + // We start searching for transactions. For performance reasons, there are limits + // to the search: a maximum number of results and a maximum number of transactions + // to search in + // TODO: Make these values configurable + $maxResults = 50; + $maxTransactionsToSearchIn = 1000; + + // Dispatch the actual work to a matched object + $matchingTransactions = + (new TransactionMatcher($triggers)) + ->setTransactionLimit($maxTransactionsToSearchIn) + ->findMatchingTransactions($maxResults); + + // Warn the user if only a subset of transactions is returned + if(count( $matchingTransactions ) == $maxResults) { + $warning = trans('firefly.warning_transaction_subset', [ 'max_num_transactions' => $maxResults ] ); + } else if(count($matchingTransactions) == 0){ + $warning = trans('firefly.warning_no_matching_transactions', [ 'num_transactions' => $maxTransactionsToSearchIn ] ); + } else { + $warning = ""; + } + + // Return json response + $view = view('list.journals-tiny', [ 'transactions' => $matchingTransactions ])->render(); + + return Response::json(['html' => $view, 'warning' => $warning ]); + } + + /** + * Returns a list of triggers as provided in the URL + * @return array + */ + protected function getTriggerList() { + $triggers = []; + $order = 1; + $data = [ + 'rule-triggers' => Input::get('rule-trigger'), + 'rule-trigger-values' => Input::get('rule-trigger-value'), + 'rule-trigger-stop' => Input::get('rule-trigger-stop'), + ]; + + foreach ($data['rule-triggers'] as $index => $trigger) { + $value = $data['rule-trigger-values'][$index]; + $stopProcessing = isset($data['rule-trigger-stop'][$index]) ? true : false; + + // Create a new trigger object + $ruleTrigger = new RuleTrigger; + $ruleTrigger->order = $order; + $ruleTrigger->active = 1; + $ruleTrigger->stop_processing = $stopProcessing; + $ruleTrigger->trigger_type = $trigger; + $ruleTrigger->trigger_value = $value; + + // Store in list + $triggers[] = $ruleTrigger; + $order++; + } + + return $triggers; + } + private function createDefaultRule() { /** @var RuleRepositoryInterface $repository */ diff --git a/app/Http/routes.php b/app/Http/routes.php index 5e16686d9a..c930d03514 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -272,7 +272,8 @@ Route::group( Route::get('/rules/rules/down/{rule}', ['uses' => 'RuleController@down', 'as' => 'rules.rule.down']); Route::get('/rules/rules/edit/{rule}', ['uses' => 'RuleController@edit', 'as' => 'rules.rule.edit']); Route::get('/rules/rules/delete/{rule}', ['uses' => 'RuleController@delete', 'as' => 'rules.rule.delete']); - + Route::get('/rules/rules/test_triggers', ['uses' => 'RuleController@testTriggers', 'as' => 'rules.rule.test_triggers']); + // rules POST: Route::post('/rules/rules/trigger/reorder/{rule}', ['uses' => 'RuleController@reorderRuleTriggers']); Route::post('/rules/rules/action/reorder/{rule}', ['uses' => 'RuleController@reorderRuleActions']); diff --git a/app/Rules/TransactionMatcher.php b/app/Rules/TransactionMatcher.php new file mode 100644 index 0000000000..629cdaa112 --- /dev/null +++ b/app/Rules/TransactionMatcher.php @@ -0,0 +1,148 @@ +setTriggers($triggers); + } + + /** + * Find matching transactions for the current set of triggers + * @param number $maxResults The maximum number of transactions returned + */ + public function findMatchingTransactions($maxResults = 50) { + /** @var JournalRepositoryInterface $repository */ + $repository = app('FireflyIII\Repositories\Journal\JournalRepositoryInterface'); + + // We don't know the number of transaction to fetch from the database, in + // order to return the proper number of matching transactions. Since we don't want + // to fetch all transactions (as the first transactions already match, or the last + // transactions are irrelevant), we will fetch data in pages. + + // The optimal pagesize is somewhere between the maximum number of results to be returned + // and the maximum number of transactions to consider. + $pagesize = min($this->maxTransactionsToSearchIn / 2, $maxResults * 2); + + // Variables used within the loop + $numTransactionsProcessed = 0; + $page = 1; + $matchingTransactions = []; + + // Flags to indicate the end of the loop + $reachedEndOfList = false; + $foundEnoughTransactions = false; + $searchedEnoughTransactions = false; + + // Start a loop to fetch batches of transactions. The loop will finish if: + // - all transactions have been fetched from the database + // - the maximum number of transactions to return has been found + // - the maximum number of transactions to search in have been searched + do { + // Fetch a batch of transactions from the database + $offset = $page > 0 ? ($page - 1) * $pagesize : 0; + $transactions = $repository->getJournalsOfTypes( $this->transactionTypes, $offset, $page, $pagesize)->getCollection()->all(); + + // Filter transactions that match the rule + $matchingTransactions += array_filter( $transactions, function($transaction) { + $processor = new Processor(new Rule, $transaction); + return $processor->isTriggeredBy($this->triggers); + }); + + // Update counters + $page++; + $numTransactionsProcessed += count($transactions); + + // Check for conditions to finish the loop + $reachedEndOfList = (count($transactions) < $pagesize); + $foundEnoughTransactions = (count($matchingTransactions) >= $maxResults); + $searchedEnoughTransactions = ($numTransactionsProcessed >= $this->maxTransactionsToSearchIn); + } while( !$reachedEndOfList && !$foundEnoughTransactions && !$searchedEnoughTransactions); + + // If the list of matchingTransactions is larger than the maximum number of results + // (e.g. if a large percentage of the transactions match), truncate the list + $matchingTransactions = array_slice($matchingTransactions, 0, $maxResults); + + return $matchingTransactions; + } + + /** + * @return array + */ + public function getTriggers() { + return $this->triggers; + } + + /** + * @param array $triggers + */ + public function setTriggers($triggers) { + $this->triggers = $triggers; + return $this; + } + + /** + * @return array + */ + public function getTransactionLimit() { + return $this->maxTransactionsToSearchIn; + } + + /** + * @param int $limit + */ + public function setTransactionLimit(int $limit) { + $this->maxTransactionsToSearchIn = $limit; + return $this; + } + + /** + * @return array + */ + public function getTransactionTypes() { + return $this->transactionTypes; + } + + /** + * @param array $transactionTypes + */ + public function setTransactionTypes(array $transactionTypes) { + $this->transactionTypes = $transactionTypes; + return $this; + } + +} diff --git a/resources/views/rules/partials/test-trigger-modal.twig b/resources/views/rules/partials/test-trigger-modal.twig new file mode 100644 index 0000000000..8239d0d88f --- /dev/null +++ b/resources/views/rules/partials/test-trigger-modal.twig @@ -0,0 +1,22 @@ + + \ No newline at end of file diff --git a/resources/views/rules/rule/create.twig b/resources/views/rules/rule/create.twig index 3361e454fe..6edc787b25 100644 --- a/resources/views/rules/rule/create.twig +++ b/resources/views/rules/rule/create.twig @@ -61,11 +61,14 @@


{{ 'add_rule_trigger'|_ }} + {{ 'test_rule_triggers'|_ }}

+ + {% include '/rules/partials/test-trigger-modal.twig' %}
diff --git a/resources/views/rules/rule/edit.twig b/resources/views/rules/rule/edit.twig index bda2c3eae9..72b2037f1f 100644 --- a/resources/views/rules/rule/edit.twig +++ b/resources/views/rules/rule/edit.twig @@ -62,11 +62,14 @@


{{ 'add_rule_trigger'|_ }} + {{ 'test_rule_triggers'|_ }}

+ + {% include '/rules/partials/test-trigger-modal.twig' %}
From 5dc556f0af3ca2311043fbd7d55459a9b51f58ba Mon Sep 17 00:00:00 2001 From: Robert Horlings Date: Wed, 17 Feb 2016 12:11:00 +0100 Subject: [PATCH 4/9] Updated frontend to access the 'test-rules' functionality --- public/css/firefly.css | 4 +++- public/js/rules/create-edit.js | 29 +++++++++++++++++++++++++++++ public/js/rules/create.js | 6 ++++++ public/js/rules/edit.js | 6 ++++++ resources/lang/en_US/firefly.php | 4 ++++ resources/lang/nl_NL/firefly.php | 4 ++++ 6 files changed, 52 insertions(+), 1 deletion(-) diff --git a/public/css/firefly.css b/public/css/firefly.css index 9843f2f058..4ce8b95c80 100644 --- a/public/css/firefly.css +++ b/public/css/firefly.css @@ -37,4 +37,6 @@ /* cursors */ .rule-triggers {cursor:move;} -.rule-actions {cursor:move;} \ No newline at end of file +.rule-actions {cursor:move;} + +#testTriggerModal .modal-body { max-height: 500px; overflow-y: scroll; } diff --git a/public/js/rules/create-edit.js b/public/js/rules/create-edit.js index 9310d6d8de..9a4c0c812c 100644 --- a/public/js/rules/create-edit.js +++ b/public/js/rules/create-edit.js @@ -82,4 +82,33 @@ function removeAction(e) { if($('.rule-action-tbody tr').length == 0) { addNewAction(); } +} + +function testRuleTriggers() { + "use strict"; + + // Serialize all trigger data + var triggerData = $( ".rule-trigger-tbody" ).find( "input[type=text], input[type=checkbox], select" ).serializeArray(); + + // Find a list of existing transactions that match these triggers + $.get('rules/rules/test_triggers', triggerData).done(function (data) { + var modal = $( "#testTriggerModal" ); + var numTriggers = $( ".rule-trigger-body > tr" ).length; + + // Set title and body + modal.find( ".transactions-list" ).html(data.html); + + // Show warning if appropriate + if( data.warning ) { + modal.find( ".transaction-warning .warning-contents" ).text(data.warning); + modal.find( ".transaction-warning" ).show(); + } else { + modal.find( ".transaction-warning" ).hide(); + } + + // Show the modal dialog + $( "#testTriggerModal" ).modal(); + }).fail(function () { + alert('Cannot get transactions for given triggers.'); + }); } \ No newline at end of file diff --git a/public/js/rules/create.js b/public/js/rules/create.js index 617cc284ee..4910378c74 100644 --- a/public/js/rules/create.js +++ b/public/js/rules/create.js @@ -31,4 +31,10 @@ $(function () { return false; }); + + $('.test_rule_triggers').click(function () { + testRuleTriggers(); + + return false; + }); }); diff --git a/public/js/rules/edit.js b/public/js/rules/edit.js index dc4ab331a5..39876d8c2c 100644 --- a/public/js/rules/edit.js +++ b/public/js/rules/edit.js @@ -24,6 +24,12 @@ $(function () { return false; }); + $('.test_rule_triggers').click(function () { + testRuleTriggers(); + + return false; + }); + $('.add_rule_action').click(function () { addNewAction(); diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 63a8aab69a..ab85aa5a6a 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -126,6 +126,10 @@ return [ 'delete_rule' => 'Delete rule ":title"', 'update_rule' => 'Update rule', + 'test_rule_triggers' => 'See matching transactions', + 'warning_transaction_subset' => 'For performance reasons this list is limited to :max_num_transactions and may only show a subset of matching transactions', + 'warning_no_matching_transactions' => 'No matching transactions found. Please note that for performance reasons, only the last :num_transactions transactions have been checked.', + // actions and triggers 'rule_trigger_user_action' => 'User action is ":trigger_value"', 'rule_trigger_from_account_starts' => 'Source account starts with ":trigger_value"', diff --git a/resources/lang/nl_NL/firefly.php b/resources/lang/nl_NL/firefly.php index 3fbdfc6d6c..b263512635 100644 --- a/resources/lang/nl_NL/firefly.php +++ b/resources/lang/nl_NL/firefly.php @@ -125,6 +125,10 @@ return [ 'edit_rule' => 'Wijzig regel ":title"', 'update_rule' => 'Werk regel bij', + 'test_rule_triggers' => 'Transacties die voldoen aan triggers', + 'warning_transaction_subset' => 'In verband met de snelheid, worden in deze lijst maximaal :max_num_transactions transacties weergegeven. Het kan daarom zijn dat transacties ontbreken in deze lijst.', + 'warning_no_matching_transactions' => 'Er zijn geen transacties gevonden die voldoen aan de triggers in de laatste :num_transactions transacties.', + // actions and triggers 'rule_trigger_user_action' => 'Gebruikersactie is ":trigger_value"', 'rule_trigger_from_account_starts' => 'Bronrekeningnaam begint met ":trigger_value"', From bc3d64a2fff006d6726633d1c9bf096dc7c8d0e6 Mon Sep 17 00:00:00 2001 From: Robert Horlings Date: Wed, 17 Feb 2016 13:13:23 +0100 Subject: [PATCH 5/9] Moved creation of Trigger objects to factory for reuse --- app/Rules/Processor.php | 15 ++---- app/Rules/Triggers/TriggerFactory.php | 69 +++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 app/Rules/Triggers/TriggerFactory.php diff --git a/app/Rules/Processor.php b/app/Rules/Processor.php index 1b1d78341b..b8a53664fd 100644 --- a/app/Rules/Processor.php +++ b/app/Rules/Processor.php @@ -16,6 +16,7 @@ use FireflyIII\Models\RuleTrigger; use FireflyIII\Models\TransactionJournal; use FireflyIII\Rules\Actions\ActionInterface; use FireflyIII\Rules\Triggers\TriggerInterface; +use FireflyIII\Rules\Triggers\TriggerFactory; use FireflyIII\Support\Domain; use Log; @@ -147,19 +148,9 @@ class Processor /** @var RuleTrigger $trigger */ foreach ($triggers as $trigger) { $foundTriggers++; - $type = $trigger->trigger_type; - - if (!isset($this->triggerTypes[$type])) { - abort(500, 'No such trigger exists ("' . $type . '").'); - } - - $class = $this->triggerTypes[$type]; - Log::debug('Trigger #' . $trigger->id . ' for rule #' . $trigger->rule_id . ' (' . $type . ')'); - if (!class_exists($class)) { - abort(500, 'Could not instantiate class for rule trigger type "' . $type . '" (' . $class . ').'); - } + /** @var TriggerInterface $triggerClass */ - $triggerClass = new $class($trigger, $this->journal); + $triggerClass = TriggerFactory::getTrigger($trigger, $this->journal); if ($triggerClass->triggered()) { $hitTriggers++; } diff --git a/app/Rules/Triggers/TriggerFactory.php b/app/Rules/Triggers/TriggerFactory.php new file mode 100644 index 0000000000..cb7c68efd2 --- /dev/null +++ b/app/Rules/Triggers/TriggerFactory.php @@ -0,0 +1,69 @@ +trigger_type; + $class = self::getTriggerClass($triggerType); + + return new $class($trigger, $journal); + } + + /** + * Returns a map with triggertypes, mapped to the class representing that type + */ + protected static function getTriggerTypes() { + if( !self::$triggerTypes ) { + self::$triggerTypes = Domain::getRuleTriggers(); + } + + return self::$triggerTypes; + } +} From 7ec5cce2c883e81995477a48000941fd9a0785db Mon Sep 17 00:00:00 2001 From: Robert Horlings Date: Wed, 17 Feb 2016 16:23:43 +0100 Subject: [PATCH 6/9] Implemented filter not to return all transactions when testing filters --- app/Http/Controllers/RuleController.php | 17 ++++++++++++----- resources/lang/en_US/firefly.php | 1 + resources/lang/nl_NL/firefly.php | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/RuleController.php b/app/Http/Controllers/RuleController.php index 3b15ca91f9..af99d30a9c 100644 --- a/app/Http/Controllers/RuleController.php +++ b/app/Http/Controllers/RuleController.php @@ -339,7 +339,11 @@ class RuleController extends Controller */ public function testTriggers() { // Create a list of triggers - $triggers = $this->getTriggerList(); + $triggers = $this->getValidTriggerList(); + + if(count($triggers) == 0) { + return Response::json(['html' => '', 'warning' => trans('firefly.warning_no_valid_triggers') ]); + } // We start searching for transactions. For performance reasons, there are limits // to the search: a maximum number of results and a maximum number of transactions @@ -370,10 +374,11 @@ class RuleController extends Controller } /** - * Returns a list of triggers as provided in the URL + * Returns a list of triggers as provided in the URL. + * Only returns triggers that will not match any transaction * @return array */ - protected function getTriggerList() { + protected function getValidTriggerList() { $triggers = []; $order = 1; $data = [ @@ -395,8 +400,10 @@ class RuleController extends Controller $ruleTrigger->trigger_value = $value; // Store in list - $triggers[] = $ruleTrigger; - $order++; + if( !$ruleTrigger->matchesAnything() ) { + $triggers[] = $ruleTrigger; + $order++; + } } return $triggers; diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index ab85aa5a6a..e9ed71aa0c 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -129,6 +129,7 @@ return [ 'test_rule_triggers' => 'See matching transactions', 'warning_transaction_subset' => 'For performance reasons this list is limited to :max_num_transactions and may only show a subset of matching transactions', 'warning_no_matching_transactions' => 'No matching transactions found. Please note that for performance reasons, only the last :num_transactions transactions have been checked.', + 'warning_no_valid_triggers' => 'No valid triggers provided.', // actions and triggers 'rule_trigger_user_action' => 'User action is ":trigger_value"', diff --git a/resources/lang/nl_NL/firefly.php b/resources/lang/nl_NL/firefly.php index b263512635..9288305e27 100644 --- a/resources/lang/nl_NL/firefly.php +++ b/resources/lang/nl_NL/firefly.php @@ -128,6 +128,7 @@ return [ 'test_rule_triggers' => 'Transacties die voldoen aan triggers', 'warning_transaction_subset' => 'In verband met de snelheid, worden in deze lijst maximaal :max_num_transactions transacties weergegeven. Het kan daarom zijn dat transacties ontbreken in deze lijst.', 'warning_no_matching_transactions' => 'Er zijn geen transacties gevonden die voldoen aan de triggers in de laatste :num_transactions transacties.', + 'warning_no_valid_triggers' => 'Geen geldige triggers opgegeven.', // actions and triggers 'rule_trigger_user_action' => 'Gebruikersactie is ":trigger_value"', From 3a33ac1455e307754b16af77b92e6b140e362c40 Mon Sep 17 00:00:00 2001 From: Robert Horlings Date: Wed, 17 Feb 2016 16:29:32 +0100 Subject: [PATCH 7/9] Removed code left over from merge --- app/Rules/Processor.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/app/Rules/Processor.php b/app/Rules/Processor.php index e60e30f024..a89d2def1f 100644 --- a/app/Rules/Processor.php +++ b/app/Rules/Processor.php @@ -17,7 +17,6 @@ use FireflyIII\Models\TransactionJournal; use FireflyIII\Rules\Actions\ActionInterface; use FireflyIII\Rules\Triggers\TriggerInterface; use FireflyIII\Rules\Triggers\TriggerFactory; -use FireflyIII\Support\Domain; use Log; /** @@ -31,10 +30,6 @@ class Processor protected $journal; /** @var Rule */ protected $rule; - /** @var array */ - private $actionTypes = []; - /** @var array */ - private $triggerTypes = []; /** * Processor constructor. @@ -46,8 +41,6 @@ class Processor { $this->rule = $rule; $this->journal = $journal; - $this->triggerTypes = Domain::getRuleTriggers(); - $this->actionTypes = Domain::getRuleActions(); } /** @@ -119,12 +112,6 @@ class Processor * @var RuleAction $action */ foreach ($this->rule->ruleActions()->orderBy('order', 'ASC')->get() as $action) { - $type = $action->action_type; - $class = $this->actionTypes[$type]; - Log::debug('Action #' . $action->id . ' for rule #' . $action->rule_id . ' (' . $type . ')'); - if (!class_exists($class)) { - abort(500, 'Could not instantiate class for rule action type "' . $type . '" (' . $class . ').'); - } /** @var ActionInterface $actionClass */ $actionClass = ActionFactory::getAction($action, $this->journal); $actionClass->act(); From 7840a5ea494d93d94007b656eba284337010ef75 Mon Sep 17 00:00:00 2001 From: Robert Horlings Date: Wed, 17 Feb 2016 16:30:54 +0100 Subject: [PATCH 8/9] Added missing import --- app/Rules/Processor.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Rules/Processor.php b/app/Rules/Processor.php index a89d2def1f..52ece1a647 100644 --- a/app/Rules/Processor.php +++ b/app/Rules/Processor.php @@ -15,6 +15,7 @@ use FireflyIII\Models\RuleAction; use FireflyIII\Models\RuleTrigger; use FireflyIII\Models\TransactionJournal; use FireflyIII\Rules\Actions\ActionInterface; +use FireflyIII\Rules\Actions\ActionFactory; use FireflyIII\Rules\Triggers\TriggerInterface; use FireflyIII\Rules\Triggers\TriggerFactory; use Log; From 919187f7fdd984fd3696155ad6a1ce708e8cc772 Mon Sep 17 00:00:00 2001 From: Robert Horlings Date: Wed, 17 Feb 2016 16:39:26 +0100 Subject: [PATCH 9/9] Made performance settings for testing triggers configurable --- app/Http/Controllers/RuleController.php | 8 ++++---- config/firefly.php | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/RuleController.php b/app/Http/Controllers/RuleController.php index af99d30a9c..544df0fb96 100644 --- a/app/Http/Controllers/RuleController.php +++ b/app/Http/Controllers/RuleController.php @@ -18,6 +18,7 @@ use FireflyIII\Models\RuleGroup; use FireflyIII\Models\RuleTrigger; use FireflyIII\Repositories\Rule\RuleRepositoryInterface; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; +use FireflyIII\Rules\TransactionMatcher; use Illuminate\Database\Eloquent\Relations\HasMany; use Input; use Preferences; @@ -25,7 +26,7 @@ use Response; use Session; use URL; use View; -use FireflyIII\Rules\TransactionMatcher; +use Config; /** * Class RuleController @@ -348,9 +349,8 @@ class RuleController extends Controller // We start searching for transactions. For performance reasons, there are limits // to the search: a maximum number of results and a maximum number of transactions // to search in - // TODO: Make these values configurable - $maxResults = 50; - $maxTransactionsToSearchIn = 1000; + $maxResults = Config::get('firefly.test-triggers.limit'); + $maxTransactionsToSearchIn = Config::get('firefly.test-triggers.max_transactions_to_analyse'); // Dispatch the actual work to a matched object $matchingTransactions = diff --git a/config/firefly.php b/config/firefly.php index 48dde88d9a..911b91e25d 100644 --- a/config/firefly.php +++ b/config/firefly.php @@ -219,5 +219,11 @@ return [ 'append_description', 'prepend_description', ], - + 'test-triggers' => [ + // The maximum number of transactions shown when testing a list of triggers + 'limit' => 50, + + // The maximum number of transactions to analyse, when testing a list of triggers + 'max_transactions_to_analyse' => 1000 + ] ];