diff --git a/mailpoet/lib/Automation/Engine/Builder/UpdateWorkflowController.php b/mailpoet/lib/Automation/Engine/Builder/UpdateWorkflowController.php new file mode 100644 index 0000000000..f5ff70bb68 --- /dev/null +++ b/mailpoet/lib/Automation/Engine/Builder/UpdateWorkflowController.php @@ -0,0 +1,40 @@ +storage = $storage; + } + + public function updateWorkflow(int $id, array $data): Workflow { + // TODO: data & workflow validation (trigger existence, graph consistency, etc.) + // TODO: new revisions when content is changed + // TODO: validation when status being is changed + + $workflow = $this->storage->getWorkflow($id); + if (!$workflow) { + throw Exceptions::workflowNotFound($id); + } + + if (array_key_exists('status', $data)) { + $workflow->setStatus($data['status']); + $this->storage->updateWorkflow($workflow); + } + + $workflow = $this->storage->getWorkflow($id); + if (!$workflow) { + throw Exceptions::workflowNotFound($id); + } + return $workflow; + } +} diff --git a/mailpoet/lib/Automation/Engine/Workflows/Workflow.php b/mailpoet/lib/Automation/Engine/Workflows/Workflow.php index 0c26873376..3b9b8ee4c6 100644 --- a/mailpoet/lib/Automation/Engine/Workflows/Workflow.php +++ b/mailpoet/lib/Automation/Engine/Workflows/Workflow.php @@ -61,6 +61,10 @@ class Workflow { return $this->status; } + public function setStatus(string $status): void { + $this->status = $status; + } + public function getCreatedAt(): DateTimeImmutable { return $this->createdAt; } diff --git a/mailpoet/lib/DI/ContainerConfigurator.php b/mailpoet/lib/DI/ContainerConfigurator.php index 9594912732..fb5dbc0b02 100644 --- a/mailpoet/lib/DI/ContainerConfigurator.php +++ b/mailpoet/lib/DI/ContainerConfigurator.php @@ -110,6 +110,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\UpdateWorkflowController::class)->setPublic(true); $container->autowire(\MailPoet\Automation\Engine\Control\ActionScheduler::class)->setPublic(true); $container->autowire(\MailPoet\Automation\Engine\Control\StepRunner::class)->setPublic(true); $container->autowire(\MailPoet\Automation\Engine\Control\Steps\ActionStepRunner::class)->setPublic(true);