src/EventSubscriber/Expediting/FreightDocumentUploadSubscriber.php line 29

  1. <?php
  2. namespace App\EventSubscriber\Expediting;
  3. use App\Doctrine\Type\Scheduler\TaskStatus;
  4. use App\Event\Expediting\FreightDocumentUploadEvent;
  5. use App\Event\Expediting\FreightEventInterface;
  6. use App\Repository\Scheduler\TaskRepository;
  7. use DateTime;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. readonly class FreightDocumentUploadSubscriber implements EventSubscriberInterface
  11. {
  12.     use FreightDocumentUploadCheckerTrait;
  13.     public function __construct(
  14.         private EntityManagerInterface $entityManager,
  15.         private TaskRepository         $taskRepository,
  16.     ) {}
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             FreightDocumentUploadEvent::IDENTIFIER => ['process'0],
  21.         ];
  22.     }
  23.     public function process(FreightEventInterface $event): void
  24.     {
  25.         $freight $event->getFreight();
  26.         if (!$this->freightHasExpeditingDocuments($freight)) {
  27.             return;
  28.         }
  29.         $documentsGatheringTask $this->taskRepository->getDocumentsGatheringTask(freight$freight);
  30.         $documentsGatheringTask->setStatus(TaskStatus::COMPLETED);
  31.         $documentsGatheringTask->setCompletedOn(new DateTime());
  32.         $this->entityManager->persist($documentsGatheringTask);
  33.         $this->entityManager->flush();
  34.     }
  35. }