mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-27 17:31:09 -06:00
Refactored method to check whether a transaction is triggered by a list of triggers
This commit is contained in:
parent
e7bb4a8ec6
commit
b9620b3a21
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user