Save and load workflows in the new format, update API

[MAILPOET-4523]
This commit is contained in:
Jan Jakes
2022-09-08 15:50:25 +02:00
committed by John Oleksowicz
parent 9028ea96ec
commit 1677cc2842
11 changed files with 126 additions and 82 deletions

View File

@ -2,6 +2,7 @@
namespace MailPoet\Automation\Engine\Builder;
use MailPoet\Automation\Engine\Data\Step;
use MailPoet\Automation\Engine\Data\Workflow;
use MailPoet\Automation\Engine\Exceptions;
use MailPoet\Automation\Engine\Exceptions\UnexpectedValueException;
@ -81,15 +82,17 @@ class UpdateWorkflowController {
foreach ($steps as $id => $data) {
$existingStep = $existingSteps[$id] ?? null;
if (
!$existingStep
|| $data['id'] !== $existingStep->getId()
|| $data['type'] !== $existingStep->getType()
|| $data['key'] !== $existingStep->getKey()
|| $data['next_step_id'] !== $existingStep->getNextStepId()
) {
if (!$existingStep || !$this->stepChanged(Step::fromArray($data), $existingStep)) {
throw Exceptions::workflowStructureModificationNotSupported();
}
}
}
private function stepChanged(Step $a, Step $b): bool {
$aData = $a->toArray();
$bData = $b->toArray();
unset($aData['args']);
unset($bData['args']);
return $aData === $bData;
}
}