diff --git a/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/AtLeastOneTriggerRule.php b/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/AtLeastOneTriggerRule.php index 7b2e8b7104..3d02fbf617 100644 --- a/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/AtLeastOneTriggerRule.php +++ b/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/AtLeastOneTriggerRule.php @@ -2,6 +2,7 @@ namespace MailPoet\Automation\Engine\Validation\WorkflowRules; +use MailPoet\Automation\Engine\Data\Step; use MailPoet\Automation\Engine\Data\Workflow; use MailPoet\Automation\Engine\Exceptions; use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowNode; @@ -10,19 +11,23 @@ use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowNodeVisitor; class AtLeastOneTriggerRule implements WorkflowNodeVisitor { public const RULE_ID = 'at-least-one-trigger'; - public function initialize(Workflow $workflow): void { - foreach ($workflow->getSteps() as $step) { - if ($step->getType() === 'trigger') { - return; - } - } + /** @var bool */ + private $triggerFound = false; - throw Exceptions::workflowStructureNotValid(__('There must be at least one trigger in the workflow.', 'mailpoet'), self::RULE_ID); + public function initialize(Workflow $workflow): void { + $this->triggerFound = false; } public function visitNode(Workflow $workflow, WorkflowNode $node): void { + if ($node->getStep()->getType() === Step::TYPE_TRIGGER) { + $this->triggerFound = true; + } } public function complete(Workflow $workflow): void { + if ($this->triggerFound) { + return; + } + throw Exceptions::workflowStructureNotValid(__('There must be at least one trigger in the workflow.', 'mailpoet'), self::RULE_ID); } }