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
TriggersUnderRootRule.php
45 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 TriggersUnderRootRule implements AutomationNodeVisitor { |
| 15 | public const RULE_ID = 'triggers-under-root'; |
| 16 | |
| 17 | /** @var array<string, Step> $triggersMap */ |
| 18 | private $triggersMap = []; |
| 19 | |
| 20 | public function initialize(Automation $automation): void { |
| 21 | $this->triggersMap = []; |
| 22 | foreach ($automation->getSteps() as $step) { |
| 23 | if ($step->getType() === 'trigger') { |
| 24 | $this->triggersMap[$step->getId()] = $step; |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | public function visitNode(Automation $automation, AutomationNode $node): void { |
| 30 | $step = $node->getStep(); |
| 31 | if ($step->getType() === Step::TYPE_ROOT) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | foreach ($step->getNextStepIds() as $nextStepId) { |
| 36 | if (isset($this->triggersMap[$nextStepId])) { |
| 37 | throw Exceptions::automationStructureNotValid(__('Trigger must be a direct descendant of automation root', 'mailpoet'), self::RULE_ID); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | public function complete(Automation $automation): void { |
| 43 | } |
| 44 | } |
| 45 |