Add author to Workflow

[MAILPOET-4417]
This commit is contained in:
David Remer
2022-08-10 12:37:46 +03:00
committed by Veljko V
parent 8861909859
commit 34d94edd3e
5 changed files with 26 additions and 10 deletions

View File

@@ -19,6 +19,9 @@ class Workflow {
/** @var string */
private $name;
/** @var \WP_User */
private $author;
/** @var string */
private $status = self::STATUS_DRAFT;
@@ -38,11 +41,13 @@ class Workflow {
public function __construct(
string $name,
array $steps,
\WP_User $author,
int $id = null,
int $versionId = null
) {
$this->name = $name;
$this->steps = [];
$this->author = $author;
foreach ($steps as $step) {
$this->steps[$step->getId()] = $step;
}
@@ -92,6 +97,10 @@ class Workflow {
return $this->createdAt;
}
public function getAuthor(): \WP_User {
return $this->author;
}
public function getUpdatedAt(): DateTimeImmutable {
return $this->updatedAt;
}
@@ -142,6 +151,7 @@ class Workflow {
return [
'name' => $this->name,
'status' => $this->status,
'author' => $this->author->ID,
'created_at' => $this->createdAt->format(DateTimeImmutable::W3C),
'updated_at' => $this->updatedAt->format(DateTimeImmutable::W3C),
'activated_at' => $this->activatedAt ? $this->activatedAt->format(DateTimeImmutable::W3C) : null,
@@ -167,7 +177,11 @@ class Workflow {
public static function fromArray(array $data): self {
// TODO: validation
$workflow = new self($data['name'], self::parseSteps(Json::decode($data['steps'])));
$workflow = new self(
$data['name'],
self::parseSteps(Json::decode($data['steps'])),
new \WP_User((int)$data['author'])
);
$workflow->id = (int)$data['id'];
$workflow->versionId = (int)$data['version_id'];
$workflow->status = $data['status'];