Extract workflow step updating to a separate controller

[MAILPOET-4515]
This commit is contained in:
Jan Jakes
2022-07-27 14:28:11 +02:00
committed by Veljko V
parent fc11b2f97e
commit c9aa53df8b
3 changed files with 36 additions and 13 deletions

View File

@ -5,17 +5,21 @@ namespace MailPoet\Automation\Engine\Builder;
use MailPoet\Automation\Engine\Exceptions;
use MailPoet\Automation\Engine\Exceptions\UnexpectedValueException;
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
use MailPoet\Automation\Engine\Workflows\Step;
use MailPoet\Automation\Engine\Workflows\Workflow;
class UpdateWorkflowController {
/** @var WorkflowStorage */
private $storage;
/** @var UpdateStepsController */
private $updateStepsController;
public function __construct(
WorkflowStorage $storage
WorkflowStorage $storage,
UpdateStepsController $updateStepsController
) {
$this->storage = $storage;
$this->updateStepsController = $updateStepsController;
}
public function updateWorkflow(int $id, array $data): Workflow {
@ -43,17 +47,7 @@ class UpdateWorkflowController {
if (array_key_exists('steps', $data)) {
$this->validateWorkflowSteps($workflow, $data['steps']);
$steps = [];
foreach ($data['steps'] as $step) {
$steps[(string)$step['id']] = new Step(
$step['id'],
$step['type'],
$step['key'],
$step['next_step_id'] ?? null,
$step['args'] ?? null
);
}
$workflow->setSteps($steps);
$this->updateStepsController->updateSteps($workflow, $data['steps']);
$changed = true;
}