Refactor export generation to handle saved exports conditionally

Simplified the creation of `ExportGeneration` by introducing a `match` expression to handle cases with and without `savedExport`. This improves readability and ensures consistent handling of saved exports while normalizing configuration options.
This commit is contained in:
Julien Fastré 2025-05-26 10:28:55 +02:00
parent e8bca6a502
commit fe31cfd544
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -316,13 +316,14 @@ class ExportController extends AbstractController
$savedExport, $savedExport,
); );
$this->entityManager->persist( $deleteAt = $this->clock->now()->add(new \DateInterval('P6M'));
$exportGeneration = new ExportGeneration( $options = $this->exportConfigNormalizer->normalizeConfig($alias, $dataToNormalize);
$alias, $exportGeneration = match (null === $savedExport) {
$this->exportConfigNormalizer->normalizeConfig($alias, $dataToNormalize), true => new ExportGeneration($alias, $options, $deleteAt),
$this->clock->now()->add(new \DateInterval('P6M')), false => ExportGeneration::fromSavedExport($savedExport, $deleteAt, $options),
), };
);
$this->entityManager->persist($exportGeneration);
$this->entityManager->flush(); $this->entityManager->flush();
$this->messageBus->dispatch(new ExportRequestGenerationMessage($exportGeneration, $user)); $this->messageBus->dispatch(new ExportRequestGenerationMessage($exportGeneration, $user));