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.
This commit is contained in:
Julien Fastré 2025-03-13 14:19:00 +01:00
parent 85a9c6bb67
commit 1ebf838bde
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -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();
}
}