feat: Rework task management in PlanBundle

- 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.
This commit is contained in:
Alexandre Gain committed 2026-11-13 21:58:45 +01:00
1 parent 8696acd01c
commit 8268fad886
33 files changed
+1454 -251

No files matched your search

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+21
View File
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
/**
* The type of a task dependency edge. The order of the cases is the order of the dropdown.
*/
enum DependencyType: string
{
case EndToStart = 'end_to_start';
case EndToEnd = 'end_to_end';
case StartToStart = 'start_to_start';
case StartToEnd = 'start_to_end';
public function getLabelKey(): string
{
return 'mautic.plan.task.dependency_type.'.$this->value;
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
/**
* The RACI roles of a task assignment. The order of the cases is the order of the dropdown.
*/
enum RaciRole: string
{
case Responsible = 'responsible';
case Accountable = 'accountable';
case Consulted = 'consulted';
case Informed = 'informed';
public function getLabelKey(): string
{
return 'mautic.plan.task.raci_role.'.$this->value;
}
public function getLabelClass(): string
{
return match ($this) {
self::Responsible => 'label-success',
self::Accountable => 'label-primary',
self::Consulted => 'label-info',
self::Informed => 'label-default',
};
}
}
+243 -65
View File
@@ -11,16 +11,29 @@ use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata;
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
use Mautic\CoreBundle\Entity\FormEntity;
use MauticPlugin\PlanBundle\Validator\Constraints\EndDateAfterStartDate;
use MauticPlugin\PlanBundle\Validator\Constraints\ValidTaskParent;
use MauticPlugin\PlanBundle\Validator\Constraints\TaskDates;
use MauticPlugin\PlanBundle\Validator\Constraints\ValidTaskDependency;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\PositiveOrZero;
use Symfony\Component\Validator\Constraints\Range;
use Symfony\Component\Validator\Mapping\ClassMetadata;
/**
* A task of a plan. Every task belongs to exactly one plan, and may have a parent task in the same plan.
* A task of a plan. Every task belongs to exactly one plan.
*
* Database rules: deleting the plan deletes its tasks (ON DELETE CASCADE); deleting a task makes its
* sub-tasks top-level (parent ON DELETE SET NULL).
* Kinds (taskKind): a regular task; a milestone, whose end date is enslaved to its start date; or a
* phase, which has no status of its own — it is a collection of tasks.
*
* Dependencies: a task may depend on other tasks (TaskDependency), with the relation type End2Start,
* End2End, Start2Start or Start2End. The former parent/child tree is replaced by this dependency
* graph.
*
* RACI: a task is assigned to the plan's stakeholders through TaskRaci rows (R/A/C/I), several
* stakeholders per role.
*
* Database rules: deleting the plan deletes its tasks (ON DELETE CASCADE); deleting a task deletes
* its dependencies and RACI rows (ON DELETE CASCADE).
*/
class Task extends FormEntity implements DateRangeInterface
{
@@ -28,6 +41,11 @@ class Task extends FormEntity implements DateRangeInterface
public const TYPE_MAX_LENGTH = 64;
/**
* The planned work is whole hours, capped to keep the column sane.
*/
public const PLANNED_WORK_MAX = 100000;
private ?int $id = null;
private ?Plan $plan = null;
@@ -42,28 +60,39 @@ class Task extends FormEntity implements DateRangeInterface
private ?string $description = null;
private ?Task $parent = null;
private ?\DateTime $startDate = null;
private ?\DateTime $endDate = null;
private TaskStatus $status = TaskStatus::New;
private ?TaskKind $taskKind = null;
private ?string $definitionOfDone = null;
private ?int $plannedWork = null;
/**
* @var Collection<int, Task>
* @var Collection<int, TaskDependency>
*/
private Collection $children;
private Collection $dependencies;
/**
* @var Collection<int, TaskRaci>
*/
private Collection $raci;
public function __construct()
{
$this->children = new ArrayCollection();
$this->dependencies = new ArrayCollection();
$this->raci = new ArrayCollection();
}
public function __clone()
{
$this->id = null;
$this->children = new ArrayCollection();
$this->id = null;
$this->dependencies = new ArrayCollection();
$this->raci = new ArrayCollection();
parent::__clone();
}
@@ -95,20 +124,6 @@ class Task extends FormEntity implements DateRangeInterface
->nullable()
->build();
$builder->createManyToOne('parent', self::class)
->inversedBy('children')
->addJoinColumn('parent_id', 'id', true, false, 'SET NULL')
->build();
$builder->createOneToMany('children', self::class)
->mappedBy('parent')
->setOrderBy(['name' => 'ASC'])
->fetchExtraLazy()
->build();
$builder->addNamedField('startDate', Types::DATETIME_MUTABLE, 'start_date', true);
$builder->addNamedField('endDate', Types::DATETIME_MUTABLE, 'end_date', true);
// Mapped on the raw metadata: ClassMetadataBuilder::addField() forces every string to VARCHAR(191).
$metadata->mapField([
'fieldName' => 'status',
@@ -118,6 +133,58 @@ class Task extends FormEntity implements DateRangeInterface
'options' => ['default' => TaskStatus::New->value],
]);
$builder->addIndex(['status'], 'plan_task_status');
$metadata->mapField([
'fieldName' => 'taskKind',
'columnName' => 'task_kind',
'type' => Types::STRING,
'length' => 20,
'enumType' => TaskKind::class,
'options' => ['default' => TaskKind::Task->value],
]);
// Dates are DATE (no time): tasks are planned at day granularity.
$metadata->mapField([
'fieldName' => 'startDate',
'columnName' => 'start_date',
'type' => Types::DATE_MUTABLE,
'nullable' => true,
]);
$metadata->mapField([
'fieldName' => 'endDate',
'columnName' => 'end_date',
'type' => Types::DATE_MUTABLE,
'nullable' => true,
]);
$builder->createField('definitionOfDone', Types::TEXT)
->columnName('definition_of_done')
->nullable()
->build();
$builder->createField('plannedWork', Types::INTEGER)
->columnName('planned_work')
->nullable()
->option('unsigned', true)
->build();
// Dependencies: outgoing edges (this task depends on those) and incoming edges (those depend
// on this task). Both sides are owned by the rows; deleting a task deletes its edges.
$builder->createOneToMany('dependencies', TaskDependency::class)
->mappedBy('task')
->setOrderBy(['position' => 'ASC'])
->cascadePersist()
->cascadeRemove()
->orphanRemoval()
->build();
$builder->createOneToMany('raci', TaskRaci::class)
->mappedBy('task')
->setOrderBy(['position' => 'ASC'])
->cascadePersist()
->cascadeRemove()
->orphanRemoval()
->build();
}
public static function loadValidatorMetadata(ClassMetadata $metadata): void
@@ -127,8 +194,11 @@ class Task extends FormEntity implements DateRangeInterface
$metadata->addPropertyConstraint('plan', new NotBlank(message: 'mautic.plan.task.plan.required'));
$metadata->addPropertyConstraint('type', new NotBlank(message: 'mautic.plan.task.type.required'));
$metadata->addPropertyConstraint('type', new Length(max: self::TYPE_MAX_LENGTH));
$metadata->addConstraint(new ValidTaskParent());
$metadata->addPropertyConstraint('plannedWork', new PositiveOrZero(message: 'mautic.plan.task.planned_work.invalid'));
$metadata->addPropertyConstraint('plannedWork', new Range(notInRangeMessage: 'mautic.plan.task.planned_work.range', min: 0, max: self::PLANNED_WORK_MAX));
$metadata->addConstraint(new EndDateAfterStartDate());
$metadata->addConstraint(new TaskDates());
$metadata->addConstraint(new ValidTaskDependency());
}
public function getId(): ?int
@@ -190,19 +260,6 @@ class Task extends FormEntity implements DateRangeInterface
return $this;
}
public function getParent(): ?Task
{
return $this->parent;
}
public function setParent(?Task $parent): static
{
$this->isChanged('parent', $parent);
$this->parent = $parent;
return $this;
}
public function getStartDate(): ?\DateTime
{
return $this->startDate;
@@ -245,37 +302,158 @@ class Task extends FormEntity implements DateRangeInterface
return $this;
}
/**
* @return Collection<int, Task>
*/
public function getChildren(): Collection
public function getTaskKind(): TaskKind
{
return $this->children;
// Never null once stored (the column defaults to 'task'); a new entity reads as a plain task.
return $this->taskKind ?? TaskKind::Task;
}
/**
* True when $task is this task or one of its ancestors.
*/
public function hasAncestorOrSelf(Task $task): bool
public function setTaskKind(TaskKind $taskKind): static
{
$seen = [];
$current = $this;
while (null !== $current) {
if ($current === $task || (null !== $task->getId() && $current->getId() === $task->getId())) {
return true;
}
// Guard against a cycle that is already stored.
$key = null !== $current->getId() ? 'id'.$current->getId() : spl_object_id($current);
if (isset($seen[$key])) {
return false;
}
$seen[$key] = true;
$current = $current->getParent();
if ($taskKind !== $this->taskKind) {
// isChanged() can't log enums (they aren't stringable), so log the backing values.
$this->addChange('taskKind', [$this->taskKind?->value, $taskKind->value]);
$taskKind->enslaveDates($this);
$this->taskKind = $taskKind;
}
return false;
return $this;
}
public function getDefinitionOfDone(): ?string
{
return $this->definitionOfDone;
}
public function setDefinitionOfDone(?string $definitionOfDone): static
{
$this->isChanged('definitionOfDone', $definitionOfDone);
$this->definitionOfDone = $definitionOfDone;
return $this;
}
public function getPlannedWork(): ?int
{
return $this->plannedWork;
}
public function setPlannedWork(?int $plannedWork): static
{
$this->isChanged('plannedWork', $this->plannedWork);
$this->plannedWork = $plannedWork;
return $this;
}
/**
* @return Collection<int, TaskDependency>
*/
public function getDependencies(): Collection
{
return $this->dependencies;
}
public function addDependency(TaskDependency $dependency): static
{
if (!$this->dependencies->contains($dependency)) {
$dependency->setTask($this);
$this->dependencies->add($dependency);
}
return $this;
}
public function removeDependency(TaskDependency $dependency): static
{
$this->dependencies->removeElement($dependency);
return $this;
}
/**
* @return Collection<int, TaskRaci>
*/
public function getRaci(): Collection
{
return $this->raci;
}
/**
* Replaces the RACI rows. The form writes the whole collection: the inflector singularizes
* "raci" to "racus", so PropertyAccess can't find addRaci/removeRaci for the collection write
* and needs this setter. The back-reference is set here, so the rows persist with their task.
*
* @param iterable<int, TaskRaci> $raci
*/
public function setRaci(iterable $raci): static
{
$this->raci = new ArrayCollection();
foreach (is_array($raci) ? $raci : iterator_to_array($raci) as $row) {
$this->addRaci($row);
}
return $this;
}
public function addRaci(TaskRaci $raci): static
{
if (!$this->raci->contains($raci)) {
$raci->setTask($this);
$this->raci->add($raci);
}
return $this;
}
public function removeRaci(TaskRaci $raci): static
{
$this->raci->removeElement($raci);
return $this;
}
/**
* A textual summary of the dependencies, the transitively blocked tasks and the RACI roles —
* used by the tab tables and the list. Formerly the parent/children tree, removed in 0.13.0.
*/
public function getDependencySummary(): string
{
$parts = [];
foreach ($this->dependencies as $dependency) {
if (null === $dependency->getDependsOn()) {
continue;
}
$parts[] = sprintf(
'%s (%s)',
$dependency->getDependsOn()->getName(),
$dependency->getDependencyType()->getLabelKey(),
);
}
return implode(', ', $parts);
}
/**
* A textual summary of the task's RACI rows, for the tables.
*/
public function getRaciSummary(): string
{
$parts = [];
foreach ($this->raci as $raci) {
$names = [];
foreach ($raci->getStakeholders() as $stakeholder) {
$names[] = $stakeholder->getName();
}
if ([] === $names) {
continue;
}
$parts[] = sprintf('%s: %s', $raci->getRole()->getLabelKey(), implode(', ', $names));
}
return implode(' · ', $parts);
}
}
+119
View File
@@ -0,0 +1,119 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata;
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
/**
* One dependency edge of the task dependency graph: this task depends on the depends-on task, with
* the relation type End2Start, End2End, Start2Start or Start2End.
*
* The edge is owned by the task it belongs to (Task::$dependencies); deleting either task deletes
* the edge (ON DELETE CASCADE both sides).
*/
class TaskDependency
{
public const TABLE_NAME = 'plan_task_dependencies';
private ?int $id = null;
private ?Task $task = null;
private ?Task $dependsOn = null;
private DependencyType $dependencyType = DependencyType::EndToStart;
/**
* Display order within the task's dependency list, from 0.
*/
private int $position = 0;
public static function loadMetadata(OrmClassMetadata $metadata): void
{
$builder = new ClassMetadataBuilder($metadata);
$builder->setTable(self::TABLE_NAME)
->setCustomRepositoryClass(TaskDependencyRepository::class);
$builder->addId();
$builder->createManyToOne('task', Task::class)
->inversedBy('dependencies')
->addJoinColumn('task_id', 'id', false, false, 'CASCADE')
->build();
$builder->createManyToOne('dependsOn', Task::class)
->addJoinColumn('depends_on_id', 'id', false, false, 'CASCADE')
->build();
$metadata->mapField([
'fieldName' => 'dependencyType',
'columnName' => 'dependency_type',
'type' => Types::STRING,
'length' => 20,
'enumType' => DependencyType::class,
'options' => ['default' => DependencyType::EndToStart->value],
]);
$builder->createField('position', Types::INTEGER)
->option('default', 0)
->build();
}
public function getId(): ?int
{
return $this->id;
}
public function getTask(): ?Task
{
return $this->task;
}
public function setTask(?Task $task): static
{
$this->task = $task;
return $this;
}
public function getDependsOn(): ?Task
{
return $this->dependsOn;
}
public function setDependsOn(?Task $dependsOn): static
{
$this->dependsOn = $dependsOn;
return $this;
}
public function getDependencyType(): DependencyType
{
return $this->dependencyType;
}
public function setDependencyType(DependencyType $dependencyType): static
{
$this->dependencyType = $dependencyType;
return $this;
}
public function getPosition(): int
{
return $this->position;
}
public function setPosition(?int $position): static
{
$this->position = $position ?? 0;
return $this;
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
use Mautic\CoreBundle\Entity\CommonRepository;
/**
* @extends CommonRepository<TaskDependency>
*/
class TaskDependencyRepository extends CommonRepository
{
public function getTableAlias(): string
{
return 'td';
}
}
+40
View File
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
/**
* The kind of a task. The order of the cases is the order of the dropdown.
*/
enum TaskKind: string
{
case Task = 'task';
case Milestone = 'milestone';
case Phase = 'phase';
public function getLabelKey(): string
{
return 'mautic.plan.task.kind.'.$this->value;
}
/**
* True when this kind has no status of its own: a phase is a collection of tasks, its state comes
* from them.
*/
public function hasStatus(): bool
{
return self::Phase !== $this;
}
/**
* Applies the kind's rules to the task's dates. A milestone's end date is enslaved to its start
* date: whatever is set, the end becomes the start.
*/
public function enslaveDates(Task $task): void
{
if (self::Milestone === $this && null !== $task->getStartDate()) {
$task->setEndDate(clone $task->getStartDate());
}
}
}
+154
View File
@@ -0,0 +1,154 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata;
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
/**
* One RACI assignment of a task: a role (R/A/C/I) and the stakeholders carrying it. Several
* stakeholders may share a role; each row is one role with its stakeholder list.
*
* The row is owned by the task it belongs to (Task::$raci); deleting the task or a stakeholder
* deletes the row (ON DELETE CASCADE both sides).
*/
class TaskRaci
{
public const TABLE_NAME = 'plan_task_raci';
/**
* The join table carrying the stakeholders of a RACI row (TaskRaci -> Stakeholder).
*/
public const JOIN_TABLE_NAME = 'plan_task_raci_stakeholders';
private ?int $id = null;
private ?Task $task = null;
private RaciRole $role = RaciRole::Responsible;
/**
* @var Collection<int, Stakeholder>
*/
private Collection $stakeholders;
/**
* Display order within the task's RACI list, from 0.
*/
private int $position = 0;
public function __construct()
{
$this->stakeholders = new ArrayCollection();
}
public function __clone()
{
$this->id = null;
$this->task = null;
$this->stakeholders = new ArrayCollection();
}
public static function loadMetadata(OrmClassMetadata $metadata): void
{
$builder = new ClassMetadataBuilder($metadata);
$builder->setTable(self::TABLE_NAME)
->setCustomRepositoryClass(TaskRaciRepository::class);
$builder->addId();
$builder->createManyToOne('task', Task::class)
->inversedBy('raci')
->addJoinColumn('task_id', 'id', false, false, 'CASCADE')
->build();
$metadata->mapField([
'fieldName' => 'role',
'type' => Types::STRING,
'length' => 20,
'enumType' => RaciRole::class,
'options' => ['default' => RaciRole::Responsible->value],
]);
$builder->createManyToMany('stakeholders', Stakeholder::class)
->setJoinTable(self::JOIN_TABLE_NAME)
->addJoinColumn('raci_id', 'id', false, false, 'CASCADE')
->addInverseJoinColumn('stakeholder_id', 'id', false, false, 'CASCADE')
->build();
$builder->createField('position', Types::INTEGER)
->option('default', 0)
->build();
}
public function getId(): ?int
{
return $this->id;
}
public function getTask(): ?Task
{
return $this->task;
}
public function setTask(?Task $task): static
{
$this->task = $task;
return $this;
}
public function getRole(): RaciRole
{
return $this->role;
}
public function setRole(RaciRole $role): static
{
$this->role = $role;
return $this;
}
/**
* @return Collection<int, Stakeholder>
*/
public function getStakeholders(): Collection
{
return $this->stakeholders;
}
public function addStakeholder(Stakeholder $stakeholder): static
{
if (!$this->stakeholders->contains($stakeholder)) {
$this->stakeholders->add($stakeholder);
}
return $this;
}
public function removeStakeholder(Stakeholder $stakeholder): static
{
$this->stakeholders->removeElement($stakeholder);
return $this;
}
public function getPosition(): int
{
return $this->position;
}
public function setPosition(?int $position): static
{
$this->position = $position ?? 0;
return $this;
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Entity;
use Mautic\CoreBundle\Entity\CommonRepository;
/**
* @extends CommonRepository<TaskRaci>
*/
class TaskRaciRepository extends CommonRepository
{
public function getTableAlias(): string
{
return 'tr';
}
}
+13 -4
View File
@@ -19,7 +19,8 @@ class TaskRepository extends CommonRepository
}
/**
* Loads the plan and the parent with the tasks, so that the list doesn't query them one by one.
* Loads the plan, the dependencies (with their depends-on task) and the RACI rows (with their
* stakeholders) with the tasks, so that the list doesn't query them one by one.
*
* @param array<string, mixed> $args
*/
@@ -28,21 +29,29 @@ class TaskRepository extends CommonRepository
$alias = $this->getTableAlias();
$args['qb'] = $this->createQueryBuilder($alias)
->select($alias, 'pl', 'pa')
->select($alias, 'pl', 'dep', 'depTask', 'raci', 'raciStakeholder')
->leftJoin($alias.'.plan', 'pl')
->leftJoin($alias.'.parent', 'pa');
->leftJoin($alias.'.dependencies', 'dep')
->leftJoin('dep.dependsOn', 'depTask')
->leftJoin($alias.'.raci', 'raci')
->leftJoin('raci.stakeholders', 'raciStakeholder');
return parent::getEntities($args);
}
/**
* All tasks of a plan, ordered by name.
* All tasks of a plan, ordered by name, with their dependencies and RACI rows loaded.
*
* @return Task[]
*/
public function findByPlan(Plan $plan): array
{
return $this->createQueryBuilder('t')
->select('t', 'dep', 'depTask', 'raci', 'raciStakeholder')
->leftJoin('t.dependencies', 'dep')
->leftJoin('dep.dependsOn', 'depTask')
->leftJoin('t.raci', 'raci')
->leftJoin('raci.stakeholders', 'raciStakeholder')
->where('t.plan = :plan')
->setParameter('plan', $plan)
->orderBy('t.name', 'ASC')