Explicitly handle optional workflow ID and version ID, fix missing ID for new workflows

[MAILPOET-4629]
This commit is contained in:
Jan Jakes
2022-09-23 11:17:07 +02:00
committed by David Remer
parent 02aaba1ded
commit f4b3f9bf86
2 changed files with 22 additions and 13 deletions

View File

@ -3,6 +3,7 @@
namespace MailPoet\Automation\Engine\Data;
use DateTimeImmutable;
use MailPoet\Automation\Engine\Exceptions\InvalidStateException;
use MailPoet\Automation\Engine\Utils\Json;
class Workflow {
@ -17,10 +18,10 @@ class Workflow {
self::STATUS_TRASH,
];
/** @var int */
/** @var int|null */
private $id;
/** @var int */
/** @var int|null */
private $versionId;
/** @var string */
@ -55,13 +56,8 @@ class Workflow {
$this->name = $name;
$this->steps = $steps;
$this->author = $author;
if ($id) {
$this->id = $id;
}
if ($versionId) {
$this->versionId = $versionId;
}
$this->id = $id;
$this->versionId = $versionId;
$now = new DateTimeImmutable();
$this->createdAt = $now;
@ -69,10 +65,16 @@ class Workflow {
}
public function getId(): int {
if (!$this->id) {
throw InvalidStateException::create()->withMessage('No workflow ID was set');
}
return $this->id;
}
public function getVersionId(): int {
if (!$this->versionId) {
throw InvalidStateException::create()->withMessage('No workflow version ID was set');
}
return $this->versionId;
}