mailpoet
/
lib
/
Automation
/
Engine
/
Validation
/
AutomationRules
/
TriggerNeedsToBeFollowedByActionRule.php
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
TriggerNeedsToBeFollowedByActionRule.php
47 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 TriggerNeedsToBeFollowedByActionRule implements AutomationNodeVisitor { |
| 15 | public const RULE_ID = 'trigger-needs-to-be-followed-by-action'; |
| 16 | |
| 17 | public function initialize(Automation $automation): void { |
| 18 | } |
| 19 | |
| 20 | public function visitNode(Automation $automation, AutomationNode $node): void { |
| 21 | if (!$automation->needsFullValidation()) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | $step = $node->getStep(); |
| 26 | if ($step->getType() !== Step::TYPE_TRIGGER) { |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | $nextStepIds = $step->getNextStepIds(); |
| 31 | if (!count($nextStepIds)) { |
| 32 | throw Exceptions::automationStructureNotValid(__('A trigger needs to be followed by an action.', 'mailpoet'), self::RULE_ID); |
| 33 | } |
| 34 | |
| 35 | foreach ($nextStepIds as $nextStepsId) { |
| 36 | $step = $automation->getStep($nextStepsId); |
| 37 | if ($step && $step->getType() === Step::TYPE_ACTION) { |
| 38 | continue; |
| 39 | } |
| 40 | throw Exceptions::automationStructureNotValid(__('A trigger needs to be followed by an action.', 'mailpoet'), self::RULE_ID); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | public function complete(Automation $automation): void { |
| 45 | } |
| 46 | } |
| 47 |