From 1591700e71c1fcacee24c9fc661632d475c1332c Mon Sep 17 00:00:00 2001 From: David Remer Date: Wed, 31 Aug 2022 11:36:00 +0300 Subject: [PATCH] Return created workflow with ID when using create-from-template endpoint [MAILPOET-4533] --- .../Builder/CreateWorkflowFromTemplateController.php | 8 ++++++-- mailpoet/lib/Automation/Engine/Data/Workflow.php | 1 + .../Workflows/WorkflowsCreateFromTemplateEndpoint.php | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mailpoet/lib/Automation/Engine/Builder/CreateWorkflowFromTemplateController.php b/mailpoet/lib/Automation/Engine/Builder/CreateWorkflowFromTemplateController.php index f9f155c09c..178ac7c5ce 100644 --- a/mailpoet/lib/Automation/Engine/Builder/CreateWorkflowFromTemplateController.php +++ b/mailpoet/lib/Automation/Engine/Builder/CreateWorkflowFromTemplateController.php @@ -29,7 +29,11 @@ class CreateWorkflowFromTemplateController { throw UnexpectedValueException::create()->withMessage('Template not found.'); } - $this->storage->createWorkflow($template->getWorkflow()); - return $template->getWorkflow(); + $workflowId = $this->storage->createWorkflow($template->getWorkflow()); + $workflow = $this->storage->getWorkflow($workflowId); + if (!$workflow) { + throw UnexpectedValueException::create()->withMessage('Workflow not found.'); + } + return $workflow; } } diff --git a/mailpoet/lib/Automation/Engine/Data/Workflow.php b/mailpoet/lib/Automation/Engine/Data/Workflow.php index 132ceaef4a..bfee021901 100644 --- a/mailpoet/lib/Automation/Engine/Data/Workflow.php +++ b/mailpoet/lib/Automation/Engine/Data/Workflow.php @@ -156,6 +156,7 @@ class Workflow { public function toArray(): array { return [ + 'id' => $this->id, 'name' => $this->name, 'status' => $this->status, 'author' => $this->author->ID, diff --git a/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsCreateFromTemplateEndpoint.php b/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsCreateFromTemplateEndpoint.php index 8abc7791df..6faa9d70c8 100644 --- a/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsCreateFromTemplateEndpoint.php +++ b/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsCreateFromTemplateEndpoint.php @@ -19,8 +19,8 @@ class WorkflowsCreateFromTemplateEndpoint extends Endpoint { } public function handle(Request $request): Response { - $this->createWorkflowFromTemplateController->createWorkflow((string)$request->getParam('slug')); - return new Response(); + $workflow = $this->createWorkflowFromTemplateController->createWorkflow((string)$request->getParam('slug')); + return new Response($workflow->toArray()); } public static function getRequestSchema(): array {