Quellcode durchsuchen

Ajout de la suppression des tags orphelins après suppression d'un article

Sangfroid vor 3 Wochen
Ursprung
Commit
7b50a2cf19
1 geänderte Dateien mit 9 neuen und 2 gelöschten Zeilen
  1. 9 2
      src/Controller/ArticleController.php

+ 9 - 2
src/Controller/ArticleController.php

@@ -108,7 +108,7 @@ final class ArticleController extends AbstractController
             if ($publicationChoice !== null) {
                 $workflow->apply($article, $publicationChoice);
             }
-            
+
             $entityManager->flush();
             
             $tagService->clearOrphansTags();
@@ -124,11 +124,18 @@ final class ArticleController extends AbstractController
 
     #[Route('/{id}', name: 'app_article_delete', methods: ['POST'])]
     #[IsGranted('edit', 'article')]
-    public function delete(Request $request, Article $article, EntityManagerInterface $entityManager): Response
+    public function delete(
+        Request $request,
+        Article $article,
+        EntityManagerInterface $entityManager,
+        TagService $tagService
+
+    ): Response
     {
         if ($this->isCsrfTokenValid('delete'.$article->getId(), $request->getPayload()->getString('_token'))) {
             $entityManager->remove($article);
             $entityManager->flush();
+            $tagService->clearOrphansTags();
         }
 
         return $this->redirectToRoute('app_article_index', [], Response::HTTP_SEE_OTHER);