diff --git a/mailpoet/lib/Automation/Engine/Control/StepRunner.php b/mailpoet/lib/Automation/Engine/Control/StepRunner.php index 9a0dae9c8f..b56f00a125 100644 --- a/mailpoet/lib/Automation/Engine/Control/StepRunner.php +++ b/mailpoet/lib/Automation/Engine/Control/StepRunner.php @@ -11,6 +11,7 @@ use MailPoet\Automation\Engine\Storage\WorkflowRunStorage; use MailPoet\Automation\Engine\Storage\WorkflowStorage; use MailPoet\Automation\Engine\WordPress; use MailPoet\Automation\Engine\Workflows\Step; +use MailPoet\Automation\Engine\Workflows\StepRunner as StepRunnerInterface; use MailPoet\Automation\Engine\Workflows\WorkflowRun; use Throwable; @@ -30,6 +31,9 @@ class StepRunner { /** @var WorkflowStorage */ private $workflowStorage; + /** @var array */ + private $stepRunners; + public function __construct( ActionScheduler $actionScheduler, ActionStepRunner $actionStepRunner, @@ -46,6 +50,12 @@ class StepRunner { public function initialize(): void { $this->wordPress->addAction(Hooks::WORKFLOW_STEP, [$this, 'run']); + $this->addStepRunner(Step::TYPE_ACTION, $this->actionStepRunner); + $this->wordPress->doAction(Hooks::STEP_RUNNER_INITIALIZE, [$this]); + } + + public function addStepRunner(string $stepType, StepRunnerInterface $stepRunner): void { + $this->stepRunners[$stepType] = $stepRunner; } /** @param mixed $args */ @@ -98,8 +108,8 @@ class StepRunner { } $stepType = $step->getType(); - if ($stepType === Step::TYPE_ACTION) { - $this->actionStepRunner->run($step, $workflow, $workflowRun); + if (isset($this->stepRunners[$stepType])) { + $this->stepRunners[$stepType]->run($step, $workflow, $workflowRun); } else { throw new InvalidStateException(); } diff --git a/mailpoet/lib/Automation/Engine/Control/Steps/ActionStepRunner.php b/mailpoet/lib/Automation/Engine/Control/Steps/ActionStepRunner.php index af2f54e1fa..4099a142d3 100644 --- a/mailpoet/lib/Automation/Engine/Control/Steps/ActionStepRunner.php +++ b/mailpoet/lib/Automation/Engine/Control/Steps/ActionStepRunner.php @@ -5,10 +5,11 @@ namespace MailPoet\Automation\Engine\Control\Steps; use MailPoet\Automation\Engine\Exceptions\InvalidStateException; use MailPoet\Automation\Engine\Registry; use MailPoet\Automation\Engine\Workflows\Step; +use MailPoet\Automation\Engine\Workflows\StepRunner; use MailPoet\Automation\Engine\Workflows\Workflow; use MailPoet\Automation\Engine\Workflows\WorkflowRun; -class ActionStepRunner { +class ActionStepRunner implements StepRunner { /** @var Registry */ private $registry; diff --git a/mailpoet/lib/Automation/Engine/Hooks.php b/mailpoet/lib/Automation/Engine/Hooks.php index bdc960cb0c..025584dfcb 100644 --- a/mailpoet/lib/Automation/Engine/Hooks.php +++ b/mailpoet/lib/Automation/Engine/Hooks.php @@ -5,6 +5,7 @@ namespace MailPoet\Automation\Engine; class Hooks { public const INITIALIZE = 'mailpoet/automation/initialize'; public const API_INITIALIZE = 'mailpoet/automation/api/initialize'; + public const STEP_RUNNER_INITIALIZE = 'mailpoet/automation/step_runner/initialize'; public const TRIGGER = 'mailpoet/automation/trigger'; public const WORKFLOW_STEP = 'mailpoet/automation/workflow/step'; } diff --git a/mailpoet/lib/Automation/Engine/Workflows/Step.php b/mailpoet/lib/Automation/Engine/Workflows/Step.php index 3c2a2e7293..235fdffd6b 100644 --- a/mailpoet/lib/Automation/Engine/Workflows/Step.php +++ b/mailpoet/lib/Automation/Engine/Workflows/Step.php @@ -16,10 +16,10 @@ class Step { private $key; /** @var string|null */ - private $nextStepId; + protected $nextStepId; /** @var array */ - private $args; + protected $args; public function __construct( string $id, diff --git a/mailpoet/lib/Automation/Engine/Workflows/StepRunner.php b/mailpoet/lib/Automation/Engine/Workflows/StepRunner.php new file mode 100644 index 0000000000..6b8dbd70fa --- /dev/null +++ b/mailpoet/lib/Automation/Engine/Workflows/StepRunner.php @@ -0,0 +1,7 @@ +getSubscriber()->getId(); } ), - + 'email' => new Field( 'mailpoet:subscriber:email', Field::TYPE_STRING,