Files
mautic-marketing-program-bu…/Migrations/Version_0_5_0.php
T
2026-11-07 19:31:49 +01:00

63 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
use MauticPlugin\PlanBundle\Entity\Task;
use MauticPlugin\PlanBundle\Entity\TaskStatus;
/**
* Adds start_date, end_date and status (default "new", indexed) to plan_tasks, for installs created
* before 0.5.0. Existing tasks get the status "new". Each column is added only if missing.
*/
class Version_0_5_0 extends AbstractMigration
{
private const STATUS_INDEX = 'plan_task_status';
protected function isApplicable(Schema $schema): bool
{
$tasks = $this->concatPrefix(Task::TABLE_NAME);
if (!$schema->hasTable($tasks)) {
return false;
}
$table = $schema->getTable($tasks);
return !$table->hasColumn('start_date')
|| !$table->hasColumn('end_date')
|| !$table->hasColumn('status')
|| !$table->hasIndex(self::STATUS_INDEX);
}
protected function up(): void
{
$tasks = $this->concatPrefix(Task::TABLE_NAME);
$table = $this->entityManager->getConnection()->createSchemaManager()->introspectTable($tasks);
if (!$table->hasColumn('start_date')) {
$this->addSql("ALTER TABLE {$tasks} ADD start_date DATETIME DEFAULT NULL");
}
if (!$table->hasColumn('end_date')) {
$this->addSql("ALTER TABLE {$tasks} ADD end_date DATETIME DEFAULT NULL");
}
if (!$table->hasColumn('status')) {
$this->addSql(sprintf(
"ALTER TABLE %s ADD status VARCHAR(20) DEFAULT '%s' NOT NULL",
$tasks,
TaskStatus::New->value
));
}
if (!$table->hasIndex(self::STATUS_INDEX)) {
// Same name as in the Task mapping (index names aren't prefixed).
$this->addSql('CREATE INDEX '.self::STATUS_INDEX." ON {$tasks} (status)");
}
}
}