Add ability to permanently delete workflow

[MAILPOET-4540]
This commit is contained in:
John Oleksowicz
2022-09-20 10:29:17 -05:00
committed by David Remer
parent a4c8caa664
commit 4e82c5334b
6 changed files with 143 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
<?php declare(strict_types = 1);
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\Validator\Builder;
class WorkflowsDeleteEndpoint extends Endpoint {
/** @var WorkflowStorage */
private $workflowStorage;
public function __construct(
WorkflowStorage $workflowStorage
) {
$this->workflowStorage = $workflowStorage;
}
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);
return new Response(null);
}
public static function getRequestSchema(): array {
return [
'id' => Builder::integer()->required(),
];
}
}