Refactor export method to use FormattedExportGeneration.

Replaces direct BinaryFileResponse usage with FormattedExportGeneration for handling file exports. Removes unnecessary imports and ensures temporary file cleanup after processing.
This commit is contained in:
Julien Fastré 2025-04-08 17:29:10 +02:00
parent e37f3e7c37
commit 50c75dff1a
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -21,8 +21,6 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -120,11 +118,10 @@ class ListPersonDuplicate implements DirectExportInterface, ExportElementValidat
$temp_file = sys_get_temp_dir().'/'.uniqid('export_').'.xlsx';
$writer->save($temp_file);
$response = new BinaryFileResponse($temp_file);
$response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'export_duplicate.xlsx');
$formatted = new FormattedExportGeneration(file_get_contents($temp_file), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
unlink($temp_file);
return $response;
return $formatted;
}
public function getDescription(): string