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,
);
$this->entityManager->persist(
$exportGeneration = new ExportGeneration(
$alias,
$this->exportConfigNormalizer->normalizeConfig($alias, $dataToNormalize),
$this->clock->now()->add(new \DateInterval('P6M')),
),
);
$deleteAt = $this->clock->now()->add(new \DateInterval('P6M'));
$options = $this->exportConfigNormalizer->normalizeConfig($alias, $dataToNormalize);
$exportGeneration = match (null === $savedExport) {
true => new ExportGeneration($alias, $options, $deleteAt),
false => ExportGeneration::fromSavedExport($savedExport, $deleteAt, $options),
};
$this->entityManager->persist($exportGeneration);
$this->entityManager->flush();
$this->messageBus->dispatch(new ExportRequestGenerationMessage($exportGeneration, $user));