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

@@ -186,7 +186,9 @@ class Workflow {
// TODO: validation
$workflow = new self(
$data['name'],
self::parseSteps(Json::decode($data['steps'])),
array_map(function (array $stepData): Step {
return Step::fromArray($stepData);
}, Json::decode($data['steps'])),
new \WP_User((int)$data['author'])
);
$workflow->id = (int)$data['id'];
@@ -197,18 +199,4 @@ class Workflow {
$workflow->activatedAt = $data['activated_at'] !== null ? new DateTimeImmutable($data['activated_at']) : null;
return $workflow;
}
private static function parseSteps(array $data): array {
$steps = [];
foreach ($data as $step) {
$steps[] = new Step(
$step['id'],
$step['type'],
$step['key'],
$step['next_step_id'] ?? null,
$step['args'] ?? []
);
}
return $steps;
}
}