mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 18:13:48 +00:00
First step to async generation [WIP]
This commit is contained in:
52
src/Bundle/ChillMainBundle/Export/ExportGenerator.php
Normal file
52
src/Bundle/ChillMainBundle/Export/ExportGenerator.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
||||
use Chill\MainBundle\Entity\ExportGeneration;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\DBAL\LockMode;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final readonly class ExportGenerator
|
||||
{
|
||||
public function __construct(
|
||||
private ExportManager $exportManager,
|
||||
private StoredObjectManagerInterface $storedObjectManager,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private ExportFormHelper $exportFormHelper,
|
||||
) {}
|
||||
|
||||
public function generate(ExportGeneration $exportGeneration, User $user): void
|
||||
{
|
||||
$this->entityManager->wrapInTransaction(function () use ($exportGeneration) {
|
||||
$object = $exportGeneration->getStoredObject();
|
||||
$this->entityManager->refresh($exportGeneration, LockMode::PESSIMISTIC_WRITE);
|
||||
$this->entityManager->refresh($object, LockMode::PESSIMISTIC_WRITE);
|
||||
|
||||
if (StoredObject::STATUS_PENDING !== $object->getStatus()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$generation = $this->exportManager->generateExport(
|
||||
$exportGeneration->getExportAlias(),
|
||||
$centers = $this->exportFormHelper->savedExportDataToFormData($exportGeneration, 'centers'),
|
||||
$this->exportFormHelper->savedExportDataToFormData($exportGeneration, 'export', ['picked_centers' => $centers]),
|
||||
$this->exportFormHelper->savedExportDataToFormData($exportGeneration, 'formatter', ['picked_centers' => $centers]),
|
||||
$user,
|
||||
);
|
||||
|
||||
$this->storedObjectManager->write($exportGeneration->getStoredObject(), $generation->content, $generation->contentType);
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user