|
@@ -5,6 +5,7 @@ namespace App\Controller;
|
|
use App\Entity\Article;
|
|
use App\Entity\Article;
|
|
use App\Form\ArticleType;
|
|
use App\Form\ArticleType;
|
|
use App\Repository\ArticleRepository;
|
|
use App\Repository\ArticleRepository;
|
|
|
|
+use App\Service\TagService;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\DependencyInjection\Attribute\Target;
|
|
use Symfony\Component\DependencyInjection\Attribute\Target;
|
|
@@ -31,7 +32,8 @@ final class ArticleController extends AbstractController
|
|
Request $request,
|
|
Request $request,
|
|
EntityManagerInterface $entityManager,
|
|
EntityManagerInterface $entityManager,
|
|
#[Target('blog_publishing')]
|
|
#[Target('blog_publishing')]
|
|
- WorkflowInterface $workflow
|
|
|
|
|
|
+ WorkflowInterface $workflow,
|
|
|
|
+ TagService $tagService
|
|
): Response
|
|
): Response
|
|
{
|
|
{
|
|
$article = new Article($this->getUser());
|
|
$article = new Article($this->getUser());
|
|
@@ -58,6 +60,8 @@ final class ArticleController extends AbstractController
|
|
$entityManager->persist($article);
|
|
$entityManager->persist($article);
|
|
$entityManager->flush();
|
|
$entityManager->flush();
|
|
|
|
|
|
|
|
+ $tagService->clearOrphansTags();
|
|
|
|
+
|
|
return $this->redirectToRoute('app_article_show', ['id' => $article->getId()], Response::HTTP_SEE_OTHER);
|
|
return $this->redirectToRoute('app_article_show', ['id' => $article->getId()], Response::HTTP_SEE_OTHER);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -83,7 +87,8 @@ final class ArticleController extends AbstractController
|
|
Article $article,
|
|
Article $article,
|
|
EntityManagerInterface $entityManager,
|
|
EntityManagerInterface $entityManager,
|
|
#[Target('blog_publishing')]
|
|
#[Target('blog_publishing')]
|
|
- WorkflowInterface $workflow
|
|
|
|
|
|
+ WorkflowInterface $workflow,
|
|
|
|
+ TagService $tagService
|
|
): Response
|
|
): Response
|
|
{
|
|
{
|
|
$transitions = $workflow->getEnabledTransitions($article);
|
|
$transitions = $workflow->getEnabledTransitions($article);
|
|
@@ -105,6 +110,8 @@ final class ArticleController extends AbstractController
|
|
}
|
|
}
|
|
|
|
|
|
$entityManager->flush();
|
|
$entityManager->flush();
|
|
|
|
+
|
|
|
|
+ $tagService->clearOrphansTags();
|
|
|
|
|
|
return $this->redirectToRoute('app_article_show', ['id' => $article->getId()], Response::HTTP_SEE_OTHER);
|
|
return $this->redirectToRoute('app_article_show', ['id' => $article->getId()], Response::HTTP_SEE_OTHER);
|
|
}
|
|
}
|
|
@@ -117,11 +124,18 @@ final class ArticleController extends AbstractController
|
|
|
|
|
|
#[Route('/{id}', name: 'app_article_delete', methods: ['POST'])]
|
|
#[Route('/{id}', name: 'app_article_delete', methods: ['POST'])]
|
|
#[IsGranted('edit', 'article')]
|
|
#[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'))) {
|
|
if ($this->isCsrfTokenValid('delete'.$article->getId(), $request->getPayload()->getString('_token'))) {
|
|
$entityManager->remove($article);
|
|
$entityManager->remove($article);
|
|
$entityManager->flush();
|
|
$entityManager->flush();
|
|
|
|
+ $tagService->clearOrphansTags();
|
|
}
|
|
}
|
|
|
|
|
|
return $this->redirectToRoute('app_article_index', [], Response::HTTP_SEE_OTHER);
|
|
return $this->redirectToRoute('app_article_index', [], Response::HTTP_SEE_OTHER);
|