PluginProbe
MailPoet – Newsletters, Email Marketing, and Automation / trunk
MailPoet – Newsletters, Email Marketing, and Automation vtrunk
5.37.0 5.36.1 5.36.0 5.35.1 5.35.0 5.34.3 5.34.2 5.34.1 5.34.0 5.33.1 5.33.0 5.32.0 5.31.0 5.30.0 5.29.0 5.28.1 5.28.0 5.27.0 5.26.0 5.26.1 5.25.0 5.24.0 4.43.0 4.43.1 4.44.0 All 541 releases
mailpoet / lib / Automation / Engine / Validation / AutomationRules / NoCycleRule.php
NoCycleRule.php
40 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types = 1);
2
3 namespace MailPoet\Automation\Engine\Validation\AutomationRules;
4
5 if (!defined('ABSPATH')) exit;
6
7
8 use MailPoet\Automation\Engine\Data\Automation;
9 use MailPoet\Automation\Engine\Data\Step;
10 use MailPoet\Automation\Engine\Exceptions;
11 use MailPoet\Automation\Engine\Validation\AutomationGraph\AutomationNode;
12 use MailPoet\Automation\Engine\Validation\AutomationGraph\AutomationNodeVisitor;
13
14 class NoCycleRule implements AutomationNodeVisitor {
15 public const RULE_ID = 'no-cycle';
16
17 public function initialize(Automation $automation): void {
18 }
19
20 public function visitNode(Automation $automation, AutomationNode $node): void {
21 $step = $node->getStep();
22 $parents = $node->getParents();
23 $parentIdsMap = array_combine(
24 array_map(function (Step $parent) {
25 return $parent->getId();
26 }, $node->getParents()),
27 $parents
28 ) ?: [];
29
30 foreach ($step->getNextStepIds() as $nextStepId) {
31 if ($nextStepId === $step->getId() || isset($parentIdsMap[$nextStepId])) {
32 throw Exceptions::automationStructureNotValid(__('Cycle found in automation graph', 'mailpoet'), self::RULE_ID);
33 }
34 }
35 }
36
37 public function complete(Automation $automation): void {
38 }
39 }
40