diff --git a/mailpoet/lib/Automation/Engine/Builder/UpdateWorkflowController.php b/mailpoet/lib/Automation/Engine/Builder/UpdateWorkflowController.php index 3c7e8f008f..0ceced94d3 100644 --- a/mailpoet/lib/Automation/Engine/Builder/UpdateWorkflowController.php +++ b/mailpoet/lib/Automation/Engine/Builder/UpdateWorkflowController.php @@ -27,15 +27,20 @@ class UpdateWorkflowController { throw Exceptions::workflowNotFound($id); } + $changed = false; + if (array_key_exists('name', $data)) { - $this->checkWorkflowName($data['name']); $workflow->setName($data['name']); - $this->storage->updateWorkflow($workflow); + $changed = true; } if (array_key_exists('status', $data)) { $this->checkWorkflowStatus($data['status']); $workflow->setStatus($data['status']); + $changed = true; + } + + if ($changed) { $this->storage->updateWorkflow($workflow); } @@ -46,12 +51,6 @@ class UpdateWorkflowController { return $workflow; } - private function checkWorkflowName(string $name): void { - if (empty($name)) { - throw UnexpectedValueException::create()->withMessage(__('Workflow name must not be empty', 'mailpoet')); - } - } - private function checkWorkflowStatus(string $status): void { if (!in_array($status, [Workflow::STATUS_ACTIVE, Workflow::STATUS_INACTIVE, Workflow::STATUS_DRAFT], true)) { throw UnexpectedValueException::create()->withMessage(__(sprintf('Invalid status: %s', $status), 'mailpoet')); diff --git a/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsPutEndpoint.php b/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsPutEndpoint.php index 26856725f0..1998c665a6 100644 --- a/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsPutEndpoint.php +++ b/mailpoet/lib/Automation/Engine/Endpoints/Workflows/WorkflowsPutEndpoint.php @@ -31,7 +31,7 @@ class WorkflowsPutEndpoint extends Endpoint { public static function getRequestSchema(): array { return [ 'id' => Builder::integer()->required(), - 'name' => Builder::string(), + 'name' => Builder::string()->minLength(1), 'status' => Builder::string(), ]; }