From 1ebf838bde7dc3209d09e49a18d084c5b4577a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 13 Mar 2025 14:19:00 +0100 Subject: [PATCH] Refactor ExportRequestGenerationMessageHandler logic. Enhance the message handler to properly manage stored objects by leveraging `StoredObjectManagerInterface` and `EntityManagerInterface`. Added logic for writing generated content, updating stored object status, and ensuring data persistence with a DB flush. --- .../ExportRequestGenerationMessageHandler.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Export/Messenger/ExportRequestGenerationMessageHandler.php b/src/Bundle/ChillMainBundle/Export/Messenger/ExportRequestGenerationMessageHandler.php index 60079c982..ecb03af82 100644 --- a/src/Bundle/ChillMainBundle/Export/Messenger/ExportRequestGenerationMessageHandler.php +++ b/src/Bundle/ChillMainBundle/Export/Messenger/ExportRequestGenerationMessageHandler.php @@ -11,9 +11,12 @@ declare(strict_types=1); namespace Chill\MainBundle\Export\Messenger; +use Chill\DocStoreBundle\Entity\StoredObject; +use Chill\DocStoreBundle\Service\StoredObjectManagerInterface; use Chill\MainBundle\Export\ExportGenerator; use Chill\MainBundle\Repository\ExportGenerationRepository; use Chill\MainBundle\Repository\UserRepositoryInterface; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Messenger\Attribute\AsMessageHandler; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; @@ -24,6 +27,8 @@ final readonly class ExportRequestGenerationMessageHandler implements MessageHan private ExportGenerationRepository $repository, private UserRepositoryInterface $userRepository, private ExportGenerator $exportGenerator, + private StoredObjectManagerInterface $storedObjectManager, + private EntityManagerInterface $entityManager, ) {} public function __invoke(ExportRequestGenerationMessage $exportRequestGenerationMessage) @@ -36,6 +41,10 @@ final readonly class ExportRequestGenerationMessageHandler implements MessageHan throw new \UnexpectedValueException('User not found'); } - $this->exportGenerator->generate($exportGeneration, $user); + $generated = $this->exportGenerator->generate($exportGeneration->getExportAlias(), $exportGeneration->getOptions(), $user); + $this->storedObjectManager->write($exportGeneration->getStoredObject(), $generated->content, $generated->contentType); + $exportGeneration->getStoredObject()->setStatus(StoredObject::STATUS_READY); + + $this->entityManager->flush(); } }