AtLeastOneTriggerRule.php
3 years ago
ConsistentStepMapRule.php
3 years ago
NoCycleRule.php
2 years ago
NoDuplicateEdgesRule.php
2 years ago
NoJoinRule.php
2 years ago
NoUnreachableStepsRule.php
2 years ago
TriggerNeedsToBeFollowedByActionRule.php
2 years ago
TriggersUnderRootRule.php
2 years ago
UnknownStepRule.php
3 years ago
ValidStepArgsRule.php
3 years ago
ValidStepFiltersRule.php
2 years ago
ValidStepOrderRule.php
3 years ago
ValidStepRule.php
2 months ago
ValidStepValidationRule.php
3 years ago
index.php
3 years ago
NoCycleRule.php
40 lines
| 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 |