From 80a41db34f0de092370b418b7164001b0799d35b Mon Sep 17 00:00:00 2001 From: matthieu Date: Tue, 19 May 2026 19:57:34 +0200 Subject: [PATCH] =?UTF-8?q?feat(workflow)=20:=20prot=C3=A8ge=20la=20suppre?= =?UTF-8?q?ssion=20d'un=20workflow=20li=C3=A9=20=C3=A0=20des=20projets=20(?= =?UTF-8?q?409)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/State/WorkflowDeleteProcessor.php | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/State/WorkflowDeleteProcessor.php diff --git a/src/State/WorkflowDeleteProcessor.php b/src/State/WorkflowDeleteProcessor.php new file mode 100644 index 0000000..a0efec9 --- /dev/null +++ b/src/State/WorkflowDeleteProcessor.php @@ -0,0 +1,42 @@ + + */ +final readonly class WorkflowDeleteProcessor implements ProcessorInterface +{ + public function __construct( + private EntityManagerInterface $entityManager, + ) {} + + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): void + { + /** @var Workflow $workflow */ + $workflow = $data; + + $count = (int) $this->entityManager->getConnection()->fetchOne( + 'SELECT COUNT(*) FROM project WHERE workflow_id = :id', + ['id' => $workflow->getId()], + ); + + if ($count > 0) { + throw new HttpException(409, sprintf( + 'Workflow used by %d project(s). Reassign them before deleting.', + $count, + )); + } + + $this->entityManager->remove($workflow); + $this->entityManager->flush(); + } +}