- Introduced migration Version_0_13_0 to update task schema: - Changed start_date and end_date to DATE type, truncating time. - Added new columns: task_kind, definition_of_done, planned_work. - Removed parent_id and its index, replacing with a dependency graph. - Created new tables: plan_task_dependencies and plan_task_raci, including a join table for stakeholders. - Updated Version_0_4_0 migration to remove references to parent_id. - Refactored TaskModel to return tasks as flat rows with dependencies and RACI assignments. - Modified task table view to display tasks without hierarchical structure, adding badges for milestones and phases. - Enhanced task form to include dependencies and RACI roles, with appropriate macros for rendering. - Updated task list view to reflect new task structure and display status based on task kind. - Added new validation constraints for task dependencies and dates, ensuring no cycles or self-references. - Removed obsolete ValidTaskParent validation as parent-child relationships are no longer supported. - Updated translations to reflect changes in task management and new fields. - Revised documentation to describe new task handling and features.
138 lines
5.4 KiB
PHP
138 lines
5.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\PlanBundle\Migrations;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
use Doctrine\ORM\Tools\SchemaTool;
|
|
use Mautic\IntegrationsBundle\Migration\AbstractMigration;
|
|
use MauticPlugin\PlanBundle\Entity\Task;
|
|
use MauticPlugin\PlanBundle\Entity\TaskDependency;
|
|
use MauticPlugin\PlanBundle\Entity\TaskRaci;
|
|
|
|
/**
|
|
* Since 0.13.0 tasks are reworked:
|
|
* - start_date and end_date become DATE (no time); existing values are truncated to the date;
|
|
* - new columns task_kind (default 'task'), definition_of_done, planned_work;
|
|
* - new tables plan_task_dependencies (dependency graph) and plan_task_raci with its
|
|
* plan_task_raci_stakeholders join table;
|
|
* - the parent/child tree is dropped: parent_id and its index are removed, replaced by the
|
|
* dependency graph.
|
|
*
|
|
* Each step runs only if needed.
|
|
*/
|
|
class Version_0_13_0 extends AbstractMigration
|
|
{
|
|
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('task_kind')
|
|
|| !$table->hasColumn('definition_of_done')
|
|
|| !$table->hasColumn('planned_work')
|
|
|| $table->hasColumn('parent_id')
|
|
|| !$schema->hasTable($this->concatPrefix(TaskDependency::TABLE_NAME))
|
|
|| !$schema->hasTable($this->concatPrefix(TaskRaci::TABLE_NAME))
|
|
|| !$schema->hasTable($this->concatPrefix(TaskRaci::JOIN_TABLE_NAME));
|
|
}
|
|
|
|
protected function up(): void
|
|
{
|
|
$tasks = $this->concatPrefix(Task::TABLE_NAME);
|
|
$table = $this->entityManager->getConnection()->createSchemaManager()->introspectTable($tasks);
|
|
|
|
// New columns.
|
|
if (!$table->hasColumn('task_kind')) {
|
|
$this->addSql(sprintf(
|
|
"ALTER TABLE %s ADD task_kind VARCHAR(20) NOT NULL DEFAULT '%s'",
|
|
$tasks,
|
|
\MauticPlugin\PlanBundle\Entity\TaskKind::Task->value
|
|
));
|
|
}
|
|
if (!$table->hasColumn('definition_of_done')) {
|
|
$this->addSql("ALTER TABLE {$tasks} ADD definition_of_done LONGTEXT DEFAULT NULL");
|
|
}
|
|
if (!$table->hasColumn('planned_work')) {
|
|
$this->addSql("ALTER TABLE {$tasks} ADD planned_work INT UNSIGNED DEFAULT NULL");
|
|
}
|
|
|
|
// Dates: DATETIME -> DATE, truncating the time part.
|
|
$start = $table->getColumn('start_date');
|
|
$end = $table->getColumn('end_date');
|
|
if ('datetime' === $start->getType()->getName()) {
|
|
$this->addSql("ALTER TABLE {$tasks} MODIFY start_date DATE DEFAULT NULL");
|
|
$this->addSql("UPDATE {$tasks} SET start_date = DATE(start_date)");
|
|
}
|
|
if ('datetime' === $end->getType()->getName()) {
|
|
$this->addSql("ALTER TABLE {$tasks} MODIFY end_date DATE DEFAULT NULL");
|
|
$this->addSql("UPDATE {$tasks} SET end_date = DATE(end_date)");
|
|
}
|
|
|
|
// Drop the parent/child tree.
|
|
if ($table->hasColumn('parent_id')) {
|
|
$this->addSql("ALTER TABLE {$tasks} DROP COLUMN parent_id");
|
|
}
|
|
|
|
// New tables. Each is created when missing on its own, so a partial earlier run is repaired.
|
|
if (!$this->introspectSchema()->hasTable($this->concatPrefix(TaskDependency::TABLE_NAME))) {
|
|
foreach ($this->getCreateTableSqls(TaskDependency::class, TaskDependency::TABLE_NAME) as $sql) {
|
|
$this->addSql($sql);
|
|
}
|
|
}
|
|
if (!$this->introspectSchema()->hasTable($this->concatPrefix(TaskRaci::TABLE_NAME))) {
|
|
foreach ($this->getCreateTableSqls(TaskRaci::class, TaskRaci::TABLE_NAME) as $sql) {
|
|
$this->addSql($sql);
|
|
}
|
|
}
|
|
// The RACI join table comes with the TaskRaci entity's SQL (CREATE TABLE plan_task_raci_stakeholders),
|
|
// but it may be missing while plan_task_raci exists (a partial earlier run).
|
|
if (!$this->introspectSchema()->hasTable($this->concatPrefix(TaskRaci::JOIN_TABLE_NAME))) {
|
|
foreach ($this->getCreateTableSqls(TaskRaci::class, TaskRaci::JOIN_TABLE_NAME) as $sql) {
|
|
$this->addSql($sql);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function introspectSchema(): Schema
|
|
{
|
|
return $this->entityManager->getConnection()->createSchemaManager()->introspectSchema();
|
|
}
|
|
|
|
/**
|
|
* The CREATE TABLE statements of one of this migration's entities, from Doctrine's SchemaTool —
|
|
* the entity's table and, for TaskRaci, its join table plan_task_raci_stakeholders too.
|
|
*
|
|
* @param class-string $entityClass
|
|
*
|
|
* @return string[]
|
|
*/
|
|
private function getCreateTableSqls(string $entityClass, string $table): array
|
|
{
|
|
$schemaTool = new SchemaTool($this->entityManager);
|
|
$prefix = 'CREATE TABLE ';
|
|
$prefixes = [$prefix.$this->concatPrefix($table).' ', $prefix.$this->concatPrefix($table).'_'];
|
|
|
|
$statements = [];
|
|
foreach ($schemaTool->getCreateSchemaSql([$this->entityManager->getClassMetadata($entityClass)]) as $sql) {
|
|
foreach ($prefixes as $candidate) {
|
|
if (str_starts_with($sql, $candidate)) {
|
|
$statements[] = $sql;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ([] === $statements) {
|
|
throw new \RuntimeException('SchemaTool returned no CREATE TABLE statement for '.$table.'.');
|
|
}
|
|
|
|
return $statements;
|
|
}
|
|
}
|