mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
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:
parent
85a9c6bb67
commit
1ebf838bde
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user