Add migration for a new cancelled_at column for scheduled tasks

[MAILPOET-5755]
This commit is contained in:
 Ján Mikláš
2024-06-17 14:50:41 +02:00
committed by Ján Mikláš
parent e55a861137
commit 1918d30fcd
2 changed files with 42 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ use MailPoetVendor\Doctrine\ORM\Mapping as ORM;
class ScheduledTaskEntity { class ScheduledTaskEntity {
const STATUS_COMPLETED = 'completed'; const STATUS_COMPLETED = 'completed';
const STATUS_SCHEDULED = 'scheduled'; const STATUS_SCHEDULED = 'scheduled';
const STATUS_CANCELLED = 'cancelled';
const STATUS_PAUSED = 'paused'; const STATUS_PAUSED = 'paused';
const STATUS_INVALID = 'invalid'; const STATUS_INVALID = 'invalid';
const VIRTUAL_STATUS_RUNNING = 'running'; // For historical reasons this is stored as null in DB const VIRTUAL_STATUS_RUNNING = 'running'; // For historical reasons this is stored as null in DB
@@ -59,6 +60,12 @@ class ScheduledTaskEntity {
*/ */
private $scheduledAt; private $scheduledAt;
/**
* @ORM\Column(type="datetimetz", nullable=true)
* @var DateTimeInterface|null
*/
private $cancelledAt;
/** /**
* @ORM\Column(type="datetimetz", nullable=true) * @ORM\Column(type="datetimetz", nullable=true)
* @var DateTimeInterface|null * @var DateTimeInterface|null
@@ -155,6 +162,20 @@ class ScheduledTaskEntity {
$this->scheduledAt = $scheduledAt; $this->scheduledAt = $scheduledAt;
} }
/**
* @return DateTimeInterface|null
*/
public function getCancelledAt() {
return $this->cancelledAt;
}
/**
* @param DateTimeInterface|null $cancelledAt
*/
public function setCancelledAt($cancelledAt) {
$this->cancelledAt = $cancelledAt;
}
/** /**
* @return DateTimeInterface|null * @return DateTimeInterface|null
*/ */

View File

@@ -0,0 +1,21 @@
<?php declare(strict_types = 1);
namespace MailPoet\Migrations\Db;
use MailPoet\Entities\ScheduledTaskEntity;
use MailPoet\Migrator\DbMigration;
class Migration_20240617_122847_Db extends DbMigration {
public function run(): void {
$scheduledTasksTable = $this->getTableName(ScheduledTaskEntity::class);
$newColumn = 'cancelled_at';
if ($this->columnExists($scheduledTasksTable, $newColumn)) {
return;
}
$this->connection->executeQuery(
"ALTER TABLE `{$scheduledTasksTable}`
ADD COLUMN `{$newColumn}` TIMESTAMP NULL DEFAULT NULL"
);
}
}