diff --git a/mailpoet/lib/Automation/Engine/Builder/UpdateStepsController.php b/mailpoet/lib/Automation/Engine/Builder/UpdateStepsController.php new file mode 100644 index 0000000000..0fcc271cd6 --- /dev/null +++ b/mailpoet/lib/Automation/Engine/Builder/UpdateStepsController.php @@ -0,0 +1,28 @@ +processStep($stepData); + $steps[$step->getId()] = $step; + } + $workflow->setSteps($steps); + return $workflow; + } + + private function processStep(array $data): Step { + return new Step( + $data['id'], + $data['type'], + $data['key'], + $data['next_step_id'] ?? null, + $data['args'] ?? null + ); + } +} diff --git a/mailpoet/lib/Automation/Engine/Builder/UpdateWorkflowController.php b/mailpoet/lib/Automation/Engine/Builder/UpdateWorkflowController.php index b34d79b63a..496d3c6c94 100644 --- a/mailpoet/lib/Automation/Engine/Builder/UpdateWorkflowController.php +++ b/mailpoet/lib/Automation/Engine/Builder/UpdateWorkflowController.php @@ -5,17 +5,21 @@ namespace MailPoet\Automation\Engine\Builder; use MailPoet\Automation\Engine\Exceptions; use MailPoet\Automation\Engine\Exceptions\UnexpectedValueException; use MailPoet\Automation\Engine\Storage\WorkflowStorage; -use MailPoet\Automation\Engine\Workflows\Step; use MailPoet\Automation\Engine\Workflows\Workflow; class UpdateWorkflowController { /** @var WorkflowStorage */ private $storage; + /** @var UpdateStepsController */ + private $updateStepsController; + public function __construct( - WorkflowStorage $storage + WorkflowStorage $storage, + UpdateStepsController $updateStepsController ) { $this->storage = $storage; + $this->updateStepsController = $updateStepsController; } public function updateWorkflow(int $id, array $data): Workflow { @@ -43,17 +47,7 @@ class UpdateWorkflowController { if (array_key_exists('steps', $data)) { $this->validateWorkflowSteps($workflow, $data['steps']); - $steps = []; - foreach ($data['steps'] as $step) { - $steps[(string)$step['id']] = new Step( - $step['id'], - $step['type'], - $step['key'], - $step['next_step_id'] ?? null, - $step['args'] ?? null - ); - } - $workflow->setSteps($steps); + $this->updateStepsController->updateSteps($workflow, $data['steps']); $changed = true; } diff --git a/mailpoet/lib/DI/ContainerConfigurator.php b/mailpoet/lib/DI/ContainerConfigurator.php index 8283af8667..c89057a4d4 100644 --- a/mailpoet/lib/DI/ContainerConfigurator.php +++ b/mailpoet/lib/DI/ContainerConfigurator.php @@ -111,6 +111,7 @@ class ContainerConfigurator implements IContainerConfigurator { ->setPublic(true) ->setArgument('$container', new Reference(ContainerWrapper::class)); $container->autowire(\MailPoet\Automation\Engine\Builder\CreateWorkflowFromTemplateController::class)->setPublic(true); + $container->autowire(\MailPoet\Automation\Engine\Builder\UpdateStepsController::class)->setPublic(true); $container->autowire(\MailPoet\Automation\Engine\Builder\UpdateWorkflowController::class)->setPublic(true); $container->autowire(\MailPoet\Automation\Engine\Control\ActionScheduler::class)->setPublic(true); $container->autowire(\MailPoet\Automation\Engine\Control\StepRunner::class)->setPublic(true);