Add basic duplication ability
[MAILPOET-4540]
This commit is contained in:
committed by
David Remer
parent
35325bdf06
commit
a4c8caa664
@@ -2,15 +2,11 @@
|
||||
|
||||
namespace MailPoet\Automation\Engine\Endpoints\Workflows;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use MailPoet\API\REST\Request;
|
||||
use MailPoet\API\REST\Response;
|
||||
use MailPoet\Automation\Engine\API\Endpoint;
|
||||
use MailPoet\Automation\Engine\Builder\UpdateWorkflowController;
|
||||
use MailPoet\Automation\Engine\Data\NextStep;
|
||||
use MailPoet\Automation\Engine\Data\Step;
|
||||
use MailPoet\Automation\Engine\Data\Workflow;
|
||||
use MailPoet\Automation\Engine\Storage\WorkflowStatisticsStorage;
|
||||
use MailPoet\Automation\Engine\Mappers\WorkflowMapper;
|
||||
use MailPoet\Automation\Engine\Validation\WorkflowSchema;
|
||||
use MailPoet\Validator\Builder;
|
||||
|
||||
@@ -18,21 +14,21 @@ class WorkflowsPutEndpoint extends Endpoint {
|
||||
/** @var UpdateWorkflowController */
|
||||
private $updateController;
|
||||
|
||||
/** @var WorkflowStatisticsStorage */
|
||||
private $statisticsStorage;
|
||||
/** @var WorkflowMapper */
|
||||
private $workflowMapper;
|
||||
|
||||
public function __construct(
|
||||
UpdateWorkflowController $updateController,
|
||||
WorkflowStatisticsStorage $statisticsStorage
|
||||
WorkflowMapper $workflowMapper
|
||||
) {
|
||||
$this->updateController = $updateController;
|
||||
$this->statisticsStorage = $statisticsStorage;
|
||||
$this->workflowMapper = $workflowMapper;
|
||||
}
|
||||
|
||||
public function handle(Request $request): Response {
|
||||
$data = $request->getParams();
|
||||
$workflow = $this->updateController->updateWorkflow(intval($request->getParam('id')), $data);
|
||||
return new Response($this->buildWorkflow($workflow));
|
||||
return new Response($this->workflowMapper->buildWorkflow($workflow));
|
||||
}
|
||||
|
||||
public static function getRequestSchema(): array {
|
||||
@@ -43,31 +39,4 @@ class WorkflowsPutEndpoint extends Endpoint {
|
||||
'steps' => WorkflowSchema::getStepsSchema(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function buildWorkflow(Workflow $workflow): array {
|
||||
return [
|
||||
'id' => $workflow->getId(),
|
||||
'name' => $workflow->getName(),
|
||||
'status' => $workflow->getStatus(),
|
||||
'created_at' => $workflow->getCreatedAt()->format(DateTimeImmutable::W3C),
|
||||
'updated_at' => $workflow->getUpdatedAt()->format(DateTimeImmutable::W3C),
|
||||
'activated_at' => $workflow->getActivatedAt() ? $workflow->getActivatedAt()->format(DateTimeImmutable::W3C) : null,
|
||||
'author' => [
|
||||
'id' => $workflow->getAuthor()->ID,
|
||||
'name' => $workflow->getAuthor()->display_name,
|
||||
],
|
||||
'stats' => $this->statisticsStorage->getWorkflowStats($workflow->getId())->toArray(),
|
||||
'steps' => array_map(function (Step $step) {
|
||||
return [
|
||||
'id' => $step->getId(),
|
||||
'type' => $step->getType(),
|
||||
'key' => $step->getKey(),
|
||||
'args' => $step->getArgs(),
|
||||
'next_steps' => array_map(function (NextStep $nextStep) {
|
||||
return $nextStep->toArray();
|
||||
}, $step->getNextSteps()),
|
||||
];
|
||||
}, $workflow->getSteps()),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user