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