Run update query only once, use Builder minLength for name
[MAILPOET-4422]
This commit is contained in:
@@ -27,15 +27,20 @@ class UpdateWorkflowController {
|
|||||||
throw Exceptions::workflowNotFound($id);
|
throw Exceptions::workflowNotFound($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$changed = false;
|
||||||
|
|
||||||
if (array_key_exists('name', $data)) {
|
if (array_key_exists('name', $data)) {
|
||||||
$this->checkWorkflowName($data['name']);
|
|
||||||
$workflow->setName($data['name']);
|
$workflow->setName($data['name']);
|
||||||
$this->storage->updateWorkflow($workflow);
|
$changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('status', $data)) {
|
if (array_key_exists('status', $data)) {
|
||||||
$this->checkWorkflowStatus($data['status']);
|
$this->checkWorkflowStatus($data['status']);
|
||||||
$workflow->setStatus($data['status']);
|
$workflow->setStatus($data['status']);
|
||||||
|
$changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($changed) {
|
||||||
$this->storage->updateWorkflow($workflow);
|
$this->storage->updateWorkflow($workflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,12 +51,6 @@ class UpdateWorkflowController {
|
|||||||
return $workflow;
|
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 {
|
private function checkWorkflowStatus(string $status): void {
|
||||||
if (!in_array($status, [Workflow::STATUS_ACTIVE, Workflow::STATUS_INACTIVE, Workflow::STATUS_DRAFT], true)) {
|
if (!in_array($status, [Workflow::STATUS_ACTIVE, Workflow::STATUS_INACTIVE, Workflow::STATUS_DRAFT], true)) {
|
||||||
throw UnexpectedValueException::create()->withMessage(__(sprintf('Invalid status: %s', $status), 'mailpoet'));
|
throw UnexpectedValueException::create()->withMessage(__(sprintf('Invalid status: %s', $status), 'mailpoet'));
|
||||||
|
@@ -31,7 +31,7 @@ class WorkflowsPutEndpoint extends Endpoint {
|
|||||||
public static function getRequestSchema(): array {
|
public static function getRequestSchema(): array {
|
||||||
return [
|
return [
|
||||||
'id' => Builder::integer()->required(),
|
'id' => Builder::integer()->required(),
|
||||||
'name' => Builder::string(),
|
'name' => Builder::string()->minLength(1),
|
||||||
'status' => Builder::string(),
|
'status' => Builder::string(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user