Add activatedAt to workflow

[MAILPOET-4417]
This commit is contained in:
David Remer
2022-08-10 12:16:12 +03:00
committed by Veljko V
parent cd3e2556dd
commit 5bd994c01c
2 changed files with 13 additions and 0 deletions

View File

@@ -28,6 +28,9 @@ class Workflow {
/** @var DateTimeImmutable */ /** @var DateTimeImmutable */
private $updatedAt; private $updatedAt;
/** @var ?DateTimeImmutable */
private $activatedAt = null;
/** @var array<string, Step> */ /** @var array<string, Step> */
private $steps; private $steps;
@@ -78,6 +81,9 @@ class Workflow {
} }
public function setStatus(string $status): void { public function setStatus(string $status): void {
if ($status === self::STATUS_ACTIVE && $this->status !== self::STATUS_ACTIVE) {
$this->activatedAt = new DateTimeImmutable();
}
$this->status = $status; $this->status = $status;
$this->setUpdatedAt(); $this->setUpdatedAt();
} }
@@ -90,6 +96,10 @@ class Workflow {
return $this->updatedAt; return $this->updatedAt;
} }
public function getActivatedAt(): ?DateTimeImmutable {
return $this->activatedAt;
}
/** @return array<string, Step> */ /** @return array<string, Step> */
public function getSteps(): array { public function getSteps(): array {
return $this->steps; return $this->steps;
@@ -134,6 +144,7 @@ class Workflow {
'status' => $this->status, 'status' => $this->status,
'created_at' => $this->createdAt->format(DateTimeImmutable::W3C), 'created_at' => $this->createdAt->format(DateTimeImmutable::W3C),
'updated_at' => $this->updatedAt->format(DateTimeImmutable::W3C), 'updated_at' => $this->updatedAt->format(DateTimeImmutable::W3C),
'activated_at' => $this->activatedAt ? $this->activatedAt->format(DateTimeImmutable::W3C) : null,
'steps' => Json::encode( 'steps' => Json::encode(
array_map(function (Step $step) { array_map(function (Step $step) {
return $step->toArray(); return $step->toArray();
@@ -162,6 +173,7 @@ class Workflow {
$workflow->status = $data['status']; $workflow->status = $data['status'];
$workflow->createdAt = new DateTimeImmutable($data['created_at']); $workflow->createdAt = new DateTimeImmutable($data['created_at']);
$workflow->updatedAt = new DateTimeImmutable($data['updated_at']); $workflow->updatedAt = new DateTimeImmutable($data['updated_at']);
$workflow->activatedAt = $data['activated_at'] !== null ? new DateTimeImmutable($data['activated_at']) : null;
return $workflow; return $workflow;
} }

View File

@@ -28,6 +28,7 @@ class Migrator {
status varchar(255) NOT NULL, status varchar(255) NOT NULL,
created_at timestamp NOT NULL, created_at timestamp NOT NULL,
updated_at timestamp NOT NULL, updated_at timestamp NOT NULL,
activated_at timestamp NULL,
deleted_at timestamp NULL, deleted_at timestamp NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
); );