src/EventSubscriber/Expediting/FreightDocumentUploadSubscriber.php line 29
<?php
namespace App\EventSubscriber\Expediting;
use App\Doctrine\Type\Scheduler\TaskStatus;
use App\Event\Expediting\FreightDocumentUploadEvent;
use App\Event\Expediting\FreightEventInterface;
use App\Repository\Scheduler\TaskRepository;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
readonly class FreightDocumentUploadSubscriber implements EventSubscriberInterface
{
use FreightDocumentUploadCheckerTrait;
public function __construct(
private EntityManagerInterface $entityManager,
private TaskRepository $taskRepository,
) {}
public static function getSubscribedEvents(): array
{
return [
FreightDocumentUploadEvent::IDENTIFIER => ['process', 0],
];
}
public function process(FreightEventInterface $event): void
{
$freight = $event->getFreight();
if (!$this->freightHasExpeditingDocuments($freight)) {
return;
}
$documentsGatheringTask = $this->taskRepository->getDocumentsGatheringTask(freight: $freight);
$documentsGatheringTask->setStatus(TaskStatus::COMPLETED);
$documentsGatheringTask->setCompletedOn(new DateTime());
$this->entityManager->persist($documentsGatheringTask);
$this->entityManager->flush();
}
}