fix(project) : erreur explicite si aucun workflow à la création au lieu d'une violation NOT NULL
This commit is contained in:
+5
-2
@@ -7,6 +7,7 @@ namespace App\Module\ProjectManagement\Infrastructure\EventListener;
|
|||||||
use App\Module\ProjectManagement\Domain\Entity\Project;
|
use App\Module\ProjectManagement\Domain\Entity\Project;
|
||||||
use App\Module\ProjectManagement\Domain\Repository\WorkflowRepositoryInterface;
|
use App\Module\ProjectManagement\Domain\Repository\WorkflowRepositoryInterface;
|
||||||
use Doctrine\ORM\Event\PrePersistEventArgs;
|
use Doctrine\ORM\Event\PrePersistEventArgs;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assigns the default workflow to a project when none was provided.
|
* Assigns the default workflow to a project when none was provided.
|
||||||
@@ -26,8 +27,10 @@ final readonly class ProjectDefaultWorkflowListener
|
|||||||
$default = $this->workflowRepository->findDefault()
|
$default = $this->workflowRepository->findDefault()
|
||||||
?? ($this->workflowRepository->findBy([], ['position' => 'ASC'], 1)[0] ?? null);
|
?? ($this->workflowRepository->findBy([], ['position' => 'ASC'], 1)[0] ?? null);
|
||||||
|
|
||||||
if (null !== $default) {
|
if (null === $default) {
|
||||||
|
throw new RuntimeException('Cannot create a project: no workflow exists. Seed at least one workflow first.');
|
||||||
|
}
|
||||||
|
|
||||||
$project->setWorkflow($default);
|
$project->setWorkflow($default);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user