Extract workflow delete logic to a controller
[MAILPOET-4540]
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\Automation\Engine\Builder;
|
||||
|
||||
use MailPoet\Automation\Engine\Data\Workflow;
|
||||
use MailPoet\Automation\Engine\Exceptions;
|
||||
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
|
||||
|
||||
class DeleteWorkflowController {
|
||||
/** @var WorkflowStorage */
|
||||
private $workflowStorage;
|
||||
|
||||
public function __construct(
|
||||
WorkflowStorage $workflowStorage
|
||||
) {
|
||||
$this->workflowStorage = $workflowStorage;
|
||||
}
|
||||
|
||||
public function deleteWorkflow(int $id): Workflow {
|
||||
$workflow = $this->workflowStorage->getWorkflow($id);
|
||||
if (!$workflow) {
|
||||
throw Exceptions::workflowNotFound($id);
|
||||
}
|
||||
$this->workflowStorage->deleteWorkflow($workflow);
|
||||
return $workflow;
|
||||
}
|
||||
}
|
@@ -5,32 +5,22 @@ namespace MailPoet\Automation\Engine\Endpoints\Workflows;
|
||||
use MailPoet\API\REST\Request;
|
||||
use MailPoet\API\REST\Response;
|
||||
use MailPoet\Automation\Engine\API\Endpoint;
|
||||
use MailPoet\Automation\Engine\Data\Workflow;
|
||||
use MailPoet\Automation\Engine\Exceptions\InvalidStateException;
|
||||
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
|
||||
use MailPoet\Automation\Engine\Builder\DeleteWorkflowController;
|
||||
use MailPoet\Validator\Builder;
|
||||
|
||||
class WorkflowsDeleteEndpoint extends Endpoint {
|
||||
/** @var WorkflowStorage */
|
||||
private $workflowStorage;
|
||||
/** @var DeleteWorkflowController */
|
||||
private $deleteController;
|
||||
|
||||
public function __construct(
|
||||
WorkflowStorage $workflowStorage
|
||||
DeleteWorkflowController $deleteController
|
||||
) {
|
||||
$this->workflowStorage = $workflowStorage;
|
||||
$this->deleteController = $deleteController;
|
||||
}
|
||||
|
||||
public function handle(Request $request): Response {
|
||||
$workflowId = $request->getParam('id');
|
||||
if (!is_int($workflowId)) {
|
||||
throw InvalidStateException::create();
|
||||
}
|
||||
$existingWorkflow = $this->workflowStorage->getWorkflow($workflowId);
|
||||
if (!$existingWorkflow instanceof Workflow) {
|
||||
throw InvalidStateException::create();
|
||||
}
|
||||
$this->workflowStorage->deleteWorkflow($existingWorkflow);
|
||||
|
||||
$workflowId = intval($request->getParam('id'));
|
||||
$this->deleteController->deleteWorkflow($workflowId);
|
||||
return new Response(null);
|
||||
}
|
||||
|
||||
|
@@ -112,6 +112,7 @@ class ContainerConfigurator implements IContainerConfigurator {
|
||||
// Automation
|
||||
$container->autowire(\MailPoet\Automation\Engine\API\API::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Builder\CreateWorkflowFromTemplateController::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Builder\DeleteWorkflowController::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Builder\DuplicateWorkflowController::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Builder\UpdateStepsController::class)->setPublic(true);
|
||||
$container->autowire(\MailPoet\Automation\Engine\Builder\UpdateWorkflowController::class)->setPublic(true);
|
||||
|
Reference in New Issue
Block a user