Allow custom validation for all step types
[MAILPOET-4659]
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
namespace MailPoet\Automation\Engine\Control;
|
||||
|
||||
use MailPoet\Automation\Engine\Data\StepValidationArgs;
|
||||
use MailPoet\Automation\Engine\Integration\Step;
|
||||
use MailPoet\Validator\Schema\ObjectSchema;
|
||||
|
||||
@ -21,4 +22,7 @@ class RootStep implements Step {
|
||||
public function getSubjectKeys(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function validate(StepValidationArgs $args): void {
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,7 @@
|
||||
namespace MailPoet\Automation\Engine\Integration;
|
||||
|
||||
use MailPoet\Automation\Engine\Data\StepRunArgs;
|
||||
use MailPoet\Automation\Engine\Data\StepValidationArgs;
|
||||
|
||||
interface Action extends Step {
|
||||
public function run(StepRunArgs $args): void;
|
||||
|
||||
public function validate(StepValidationArgs $args): void;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace MailPoet\Automation\Engine\Integration;
|
||||
|
||||
use MailPoet\Automation\Engine\Data\StepValidationArgs;
|
||||
use MailPoet\Validator\Schema\ObjectSchema;
|
||||
|
||||
interface Step {
|
||||
@ -13,4 +14,6 @@ interface Step {
|
||||
|
||||
/** @return string[] */
|
||||
public function getSubjectKeys(): array;
|
||||
|
||||
public function validate(StepValidationArgs $args): void;
|
||||
}
|
||||
|
@ -44,12 +44,9 @@ class ValidStepValidationRule implements WorkflowNodeVisitor {
|
||||
}
|
||||
|
||||
try {
|
||||
if ($registryStep instanceof Action) {
|
||||
$subjects = $this->collectSubjects($workflow, $node->getParents());
|
||||
$args = new StepValidationArgs($workflow, $step, $subjects);
|
||||
$registryStep->validate($args);
|
||||
}
|
||||
|
||||
$subjects = $this->collectSubjects($workflow, $node->getParents());
|
||||
$args = new StepValidationArgs($workflow, $step, $subjects);
|
||||
$registryStep->validate($args);
|
||||
} catch (Throwable $e) {
|
||||
$this->errors[$step->getId()] = [
|
||||
'step_id' => $step->getId(),
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace MailPoet\Automation\Integrations\MailPoet\Triggers;
|
||||
|
||||
use MailPoet\Automation\Engine\Data\StepRunArgs;
|
||||
use MailPoet\Automation\Engine\Data\StepValidationArgs;
|
||||
use MailPoet\Automation\Engine\Data\Subject;
|
||||
use MailPoet\Automation\Engine\Hooks;
|
||||
use MailPoet\Automation\Engine\Integration\Trigger;
|
||||
@ -47,6 +48,9 @@ class SomeoneSubscribesTrigger implements Trigger {
|
||||
];
|
||||
}
|
||||
|
||||
public function validate(StepValidationArgs $args): void {
|
||||
}
|
||||
|
||||
public function registerHooks(): void {
|
||||
$this->wp->addAction('mailpoet_segment_subscribed', [$this, 'handleSubscription'], 10, 2);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace MailPoet\Automation\Integrations\MailPoet\Triggers;
|
||||
|
||||
use MailPoet\Automation\Engine\Data\StepRunArgs;
|
||||
use MailPoet\Automation\Engine\Data\StepValidationArgs;
|
||||
use MailPoet\Automation\Engine\Data\Subject;
|
||||
use MailPoet\Automation\Engine\Hooks;
|
||||
use MailPoet\Automation\Engine\Integration\Trigger;
|
||||
@ -56,6 +57,9 @@ class UserRegistrationTrigger implements Trigger {
|
||||
];
|
||||
}
|
||||
|
||||
public function validate(StepValidationArgs $args): void {
|
||||
}
|
||||
|
||||
public function registerHooks(): void {
|
||||
$this->wp->addAction('mailpoet_user_registered', [$this, 'handleSubscription']);
|
||||
}
|
||||
|
Reference in New Issue
Block a user