diff --git a/.changes/unreleased/Fixed-20250903-211043.yaml b/.changes/unreleased/Fixed-20250903-211043.yaml new file mode 100644 index 000000000..04a0435b5 --- /dev/null +++ b/.changes/unreleased/Fixed-20250903-211043.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: Fix exports to work with DirectExportInterface +time: 2025-09-03T21:10:43.957621699+02:00 +custom: + Issue: "" + SchemaChange: No schema change diff --git a/src/Bundle/ChillMainBundle/Controller/ExportController.php b/src/Bundle/ChillMainBundle/Controller/ExportController.php index d623a2613..da21b873a 100644 --- a/src/Bundle/ChillMainBundle/Controller/ExportController.php +++ b/src/Bundle/ChillMainBundle/Controller/ExportController.php @@ -345,7 +345,7 @@ class ExportController extends AbstractController * @param array $dataExport Raw data from export step * @param array $dataFormatter Raw data from formatter step */ - private function buildExportDataForNormalization(?string $alias, ?array $dataCenters, array $dataExport, ?array $dataFormatter, ?SavedExport $savedExport): array + private function buildExportDataForNormalization(string $alias, ?array $dataCenters, array $dataExport, ?array $dataFormatter, ?SavedExport $savedExport): array { if ($this->filterStatsByCenters) { $formCenters = $this->createCreateFormExport($alias, 'generate_centers', [], null); @@ -365,7 +365,7 @@ class ExportController extends AbstractController $formExport->submit($dataExport); $dataExport = $formExport->getData(); - if (\count($dataFormatter) > 0) { + if (is_array($dataFormatter) && \count($dataFormatter) > 0) { $formFormatter = $this->createCreateFormExport( $alias, 'generate_formatter', @@ -381,7 +381,7 @@ class ExportController extends AbstractController 'export' => $dataExport['export']['export'] ?? [], 'filters' => $dataExport['export']['filters'] ?? [], 'aggregators' => $dataExport['export']['aggregators'] ?? [], - 'pick_formatter' => $dataExport['export']['pick_formatter']['alias'], + 'pick_formatter' => ($dataExport['export']['pick_formatter'] ?? [])['alias'] ?? '', 'formatter' => $dataFormatter['formatter'] ?? [], ]; } diff --git a/src/Bundle/ChillMainBundle/Export/ExportConfigNormalizer.php b/src/Bundle/ChillMainBundle/Export/ExportConfigNormalizer.php index c94e7ba03..b71b2d102 100644 --- a/src/Bundle/ChillMainBundle/Export/ExportConfigNormalizer.php +++ b/src/Bundle/ChillMainBundle/Export/ExportConfigNormalizer.php @@ -72,10 +72,14 @@ class ExportConfigNormalizer } $serialized['aggregators'] = $aggregatorsSerialized; - $serialized['pick_formatter'] = $formData['pick_formatter']; - $formatter = $this->exportManager->getFormatter($formData['pick_formatter']); - $serialized['formatter']['form'] = $formatter->normalizeFormData($formData['formatter']); - $serialized['formatter']['version'] = $formatter->getNormalizationVersion(); + if ($export instanceof ExportInterface) { + $serialized['pick_formatter'] = $formData['pick_formatter']; + $formatter = $this->exportManager->getFormatter($formData['pick_formatter']); + $serialized['formatter']['form'] = $formatter->normalizeFormData($formData['formatter']); + $serialized['formatter']['version'] = $formatter->getNormalizationVersion(); + } elseif ($export instanceof DirectExportInterface) { + $serialized['formatter'] = ['form' => [], 'version' => 0]; + } return $serialized; } @@ -87,7 +91,12 @@ class ExportConfigNormalizer public function denormalizeConfig(string $exportAlias, array $serializedData, bool $replaceDisabledByDefaultData = false): array { $export = $this->exportManager->getExport($exportAlias); - $formater = $this->exportManager->getFormatter($serializedData['pick_formatter']); + + if ($export instanceof ExportInterface) { + $formatter = $this->exportManager->getFormatter($serializedData['pick_formatter']); + } else { + $formatter = null; + } $filtersConfig = []; foreach ($serializedData['filters'] as $alias => $filterData) { @@ -117,8 +126,8 @@ class ExportConfigNormalizer 'export' => $export->denormalizeFormData($serializedData['export']['form'], $serializedData['export']['version']), 'filters' => $filtersConfig, 'aggregators' => $aggregatorsConfig, - 'pick_formatter' => $serializedData['pick_formatter'], - 'formatter' => $formater->denormalizeFormData($serializedData['formatter']['form'], $serializedData['formatter']['version']), + 'pick_formatter' => $serializedData['pick_formatter'] ?? '', + 'formatter' => $formatter?->denormalizeFormData($serializedData['formatter']['form'], $serializedData['formatter']['version']), 'centers' => [ 'centers' => array_values(array_filter(array_map(fn (int $id) => $this->centerRepository->find($id), $serializedData['centers']['centers']), fn ($item) => null !== $item)), 'regroupments' => array_values(array_filter(array_map(fn (int $id) => $this->regroupmentRepository->find($id), $serializedData['centers']['regroupments']), fn ($item) => null !== $item)),