diff --git a/mailpoet/lib/Automation/Engine/Data/Workflow.php b/mailpoet/lib/Automation/Engine/Data/Workflow.php index 8ed86a2648..543bf7d769 100644 --- a/mailpoet/lib/Automation/Engine/Data/Workflow.php +++ b/mailpoet/lib/Automation/Engine/Data/Workflow.php @@ -28,6 +28,9 @@ class Workflow { /** @var DateTimeImmutable */ private $updatedAt; + /** @var ?DateTimeImmutable */ + private $activatedAt = null; + /** @var array */ private $steps; @@ -78,6 +81,9 @@ class Workflow { } public function setStatus(string $status): void { + if ($status === self::STATUS_ACTIVE && $this->status !== self::STATUS_ACTIVE) { + $this->activatedAt = new DateTimeImmutable(); + } $this->status = $status; $this->setUpdatedAt(); } @@ -90,6 +96,10 @@ class Workflow { return $this->updatedAt; } + public function getActivatedAt(): ?DateTimeImmutable { + return $this->activatedAt; + } + /** @return array */ public function getSteps(): array { return $this->steps; @@ -134,6 +144,7 @@ class Workflow { 'status' => $this->status, 'created_at' => $this->createdAt->format(DateTimeImmutable::W3C), 'updated_at' => $this->updatedAt->format(DateTimeImmutable::W3C), + 'activated_at' => $this->activatedAt ? $this->activatedAt->format(DateTimeImmutable::W3C) : null, 'steps' => Json::encode( array_map(function (Step $step) { return $step->toArray(); @@ -162,6 +173,7 @@ class Workflow { $workflow->status = $data['status']; $workflow->createdAt = new DateTimeImmutable($data['created_at']); $workflow->updatedAt = new DateTimeImmutable($data['updated_at']); + $workflow->activatedAt = $data['activated_at'] !== null ? new DateTimeImmutable($data['activated_at']) : null; return $workflow; } diff --git a/mailpoet/lib/Automation/Engine/Migrations/Migrator.php b/mailpoet/lib/Automation/Engine/Migrations/Migrator.php index e3f07c8852..3e33ce411e 100644 --- a/mailpoet/lib/Automation/Engine/Migrations/Migrator.php +++ b/mailpoet/lib/Automation/Engine/Migrations/Migrator.php @@ -28,6 +28,7 @@ class Migrator { status varchar(255) NOT NULL, created_at timestamp NOT NULL, updated_at timestamp NOT NULL, + activated_at timestamp NULL, deleted_at timestamp NULL, PRIMARY KEY (id) );