Skip to content

Firefly III: a personal finances manager

Merge branch 'develop' into feature/test-triggers

Robert Horlings8fdc6c11e14f
diff --cc app/Rules/Processor.php
index 1b1d78341b,bcd81a4d86..645ef47e68
--- a/app/Rules/Processor.php
+++ b/app/Rules/Processor.php
@@@ -137,49 -110,30 +126,37 @@@ class Processo
}
/**
- * 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)) {
- 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++;
}
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());
}