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

+25
View File
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* Applies the task kind's rules to the dates:
* - a milestone's end date is enslaved to its start date (saved as equals);
* - a phase keeps its own dates, like any task.
*
* The start-before-end rule itself is EndDateAfterStartDate, shared by plans and tasks.
*/
#[\Symfony\Component\Validator\Attribute\HasNamedArguments]
class TaskDates extends Constraint
{
public const MILESTONE_END_ENSLAVED = 'mautic.plan.task.milestone.end_enslaved';
public function getTargets(): string|array
{
return self::CLASS_CONSTRAINT;
}
}
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Validator\Constraints;
use MauticPlugin\PlanBundle\Entity\Task;
use MauticPlugin\PlanBundle\Entity\TaskKind;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Enforces the task kind's date rules. A milestone's end date is enslaved to its start date: the
* validator copies the start date onto the end date before validation, so the saved task always
* carries start = end.
*/
class TaskDatesValidator extends ConstraintValidator
{
/**
* @param Task $task
*/
public function validate($task, Constraint $constraint): void
{
if (!$task instanceof Task) {
return;
}
if (TaskKind::Milestone === $task->getTaskKind() && null !== $task->getStartDate()) {
$task->setEndDate(clone $task->getStartDate());
}
}
}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* A task's dependency edges must not form a cycle, and must not point at the task itself.
*/
class ValidTaskDependency extends Constraint
{
public const SELF_REFERENCE = 'mautic.plan.task.dependency.self';
public const CYCLE = 'mautic.plan.task.dependency.cycle';
public const OTHER_PLAN = 'mautic.plan.task.dependency.other_plan';
public function getTargets(): string|array
{
return self::CLASS_CONSTRAINT;
}
}
@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Validator\Constraints;
use Doctrine\ORM\EntityManagerInterface;
use MauticPlugin\PlanBundle\Entity\Task;
use MauticPlugin\PlanBundle\Entity\TaskDependency;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Walks the task's dependency edges and refuses cycles, self-edges and edges to another plan's
* tasks. The walk follows the edges through the database (edges of other tasks are not on this
* form), so a cycle crossing other tasks is caught too.
*/
class ValidTaskDependencyValidator extends ConstraintValidator
{
public function __construct(
private EntityManagerInterface $em,
) {
}
/**
* @param Task $task
*/
public function validate($task, Constraint $constraint): void
{
if (!$task instanceof Task) {
return;
}
foreach ($task->getDependencies() as $dependency) {
$this->validateEdge($task, $dependency, $constraint);
}
}
private function validateEdge(Task $task, TaskDependency $dependency, Constraint $constraint): void
{
$dependsOn = $dependency->getDependsOn();
if (null === $dependsOn) {
return;
}
if ($dependsOn === $task || $dependsOn->getId() === $task->getId()) {
$this->context->buildViolation($constraint::SELF_REFERENCE)->atPath('dependencies')->addViolation();
return;
}
if (null !== $task->getPlan() && null !== $dependsOn->getPlan() && $task->getPlan()->getId() !== $dependsOn->getPlan()->getId()) {
$this->context->buildViolation($constraint::OTHER_PLAN)->atPath('dependencies')->addViolation();
return;
}
// Cycle check: walk the edges from the depends-on task; if we come back to this task, it's a cycle.
$seen = [];
$queue = [$dependsOn];
while (null !== ($current = array_shift($queue))) {
$key = $current->getId() ?? spl_object_id($current);
if ($key === ($task->getId() ?? spl_object_id($task))) {
$this->context->buildViolation($constraint::CYCLE)->atPath('dependencies')->addViolation();
return;
}
if (isset($seen[$key])) {
continue;
}
$seen[$key] = true;
// Follow the edges of the current task, from the database (they may belong to other tasks).
$edges = $this->em->getRepository(TaskDependency::class)->findBy(['task' => $current]);
foreach ($edges as $edge) {
if (null !== $edge->getDependsOn()) {
$queue[] = $edge->getDependsOn();
}
}
}
}
}
-23
View File
@@ -1,23 +0,0 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* Class constraint on Task: the parent task must be in the same plan, and must not be the task itself
* or one of its sub-tasks (which would create a loop).
*/
class ValidTaskParent extends Constraint
{
public string $otherPlanMessage = 'mautic.plan.task.parent.other_plan';
public string $loopMessage = 'mautic.plan.task.parent.loop';
public function getTargets(): string
{
return self::CLASS_CONSTRAINT;
}
}
@@ -1,53 +0,0 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Validator\Constraints;
use MauticPlugin\PlanBundle\Entity\Task;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
class ValidTaskParentValidator extends ConstraintValidator
{
public function validate(mixed $value, Constraint $constraint): void
{
if (!$constraint instanceof ValidTaskParent) {
throw new UnexpectedTypeException($constraint, ValidTaskParent::class);
}
if (null === $value) {
return;
}
if (!$value instanceof Task) {
throw new UnexpectedValueException($value, Task::class);
}
$parent = $value->getParent();
if (null === $parent) {
return;
}
// The parent's ancestors include the task itself: the task is its own parent or a sub-task's child.
if ($parent->hasAncestorOrSelf($value)) {
$this->context->buildViolation($constraint->loopMessage)
->atPath('parent')
->addViolation();
return;
}
$plan = $value->getPlan();
$parentPlan = $parent->getPlan();
if (null !== $plan && null !== $parentPlan && $plan->getId() !== $parentPlan->getId()) {
$this->context->buildViolation($constraint->otherPlanMessage)
->atPath('parent')
->addViolation();
}
}
}