Add basic workflow update controller with status change caps
[MAILPOET-4454]
This commit is contained in:
@ -0,0 +1,40 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace MailPoet\Automation\Engine\Builder;
|
||||||
|
|
||||||
|
use MailPoet\Automation\Engine\Exceptions;
|
||||||
|
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
|
||||||
|
use MailPoet\Automation\Engine\Workflows\Workflow;
|
||||||
|
|
||||||
|
class UpdateWorkflowController {
|
||||||
|
/** @var WorkflowStorage */
|
||||||
|
private $storage;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
WorkflowStorage $storage
|
||||||
|
) {
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
@ -61,6 +61,10 @@ class Workflow {
|
|||||||
return $this->status;
|
return $this->status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setStatus(string $status): void {
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
public function getCreatedAt(): DateTimeImmutable {
|
public function getCreatedAt(): DateTimeImmutable {
|
||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
@ -110,6 +110,7 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
->setPublic(true)
|
->setPublic(true)
|
||||||
->setArgument('$container', new Reference(ContainerWrapper::class));
|
->setArgument('$container', new Reference(ContainerWrapper::class));
|
||||||
$container->autowire(\MailPoet\Automation\Engine\Builder\CreateWorkflowFromTemplateController::class)->setPublic(true);
|
$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\ActionScheduler::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Automation\Engine\Control\StepRunner::class)->setPublic(true);
|
$container->autowire(\MailPoet\Automation\Engine\Control\StepRunner::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Automation\Engine\Control\Steps\ActionStepRunner::class)->setPublic(true);
|
$container->autowire(\MailPoet\Automation\Engine\Control\Steps\ActionStepRunner::class)->setPublic(true);
|
||||||
|
Reference in New Issue
Block a user