src/EventListener/TaskSubscriber.php line 24

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\EventListener;
  4. use App\Entity\Content\Task;
  5. use App\Service\TaxonomyDurationManager;
  6. use Doctrine\ORM\Events as DoctrineEvents;
  7. use Symfony\Component\Console\ConsoleEvents;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\HttpKernel\KernelEvents;
  10. class TaskSubscriber implements EventSubscriberInterface
  11. {
  12.     private $needRefresh false;
  13.     public function __construct(
  14.         private readonly TaxonomyDurationManager $durationManager
  15.     ) {
  16.     }
  17.     public function postRemove(Task $task): void
  18.     {
  19.         if ($task->isDuration()) {
  20.             $this->needRefresh true;
  21.         }
  22.     }
  23.     public static function getSubscribedEvents(): array
  24.     {
  25.         return [
  26.             DoctrineEvents::postRemove => 'postRemove',
  27.             KernelEvents::TERMINATE => 'terminate',
  28.             ConsoleEvents::TERMINATE => 'terminate',
  29.         ];
  30.     }
  31.     public function terminate(): void
  32.     {
  33.         if ($this->needRefresh) {
  34.             $this->durationManager->refreshTaxonomiesWithDuration();
  35.         }
  36.     }
  37. }