From d74179f1e12263d1648d8183b616d2febc032aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 30 Oct 2025 00:22:22 +0100 Subject: [PATCH] Refactor CSV creation and reading to use `Reader::from` and `Writer::from`. - Replaced deprecated `createFromPath` and `createFromStream` methods with `from`. - Updated all relevant commands, services, controllers, and exporters. --- .../ChillMainBundle/Command/ChillImportUsersCommand.php | 6 +++--- .../Command/ChillUserSendRenewPasswordCodeCommand.php | 2 +- .../ChillMainBundle/Controller/UserExportController.php | 4 ++-- .../Service/Import/AddressReferenceBEFromBestAddress.php | 2 +- .../Service/Import/AddressReferenceBaseImporter.php | 2 +- .../Service/Import/AddressReferenceFromBAN.php | 2 +- .../Service/Import/AddressReferenceFromBano.php | 2 +- .../ChillMainBundle/Service/Import/AddressReferenceLU.php | 2 +- .../Service/Import/PostalCodeBEFromBestAddress.php | 2 +- .../Service/Import/PostalCodeFRFromOpenData.php | 2 +- .../ChillPersonBundle/Command/ImportSocialWorkMetadata.php | 2 +- .../DataFixtures/ORM/LoadSocialWorkMetadata.php | 2 +- .../Service/SocialWork/SocialActionCSVExportService.php | 2 +- .../Service/SocialWork/SocialIssueCSVExportService.php | 2 +- .../Controller/ThirdpartyCSVExportController.php | 2 +- 15 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Command/ChillImportUsersCommand.php b/src/Bundle/ChillMainBundle/Command/ChillImportUsersCommand.php index 238d5a0f1..ee313a000 100644 --- a/src/Bundle/ChillMainBundle/Command/ChillImportUsersCommand.php +++ b/src/Bundle/ChillMainBundle/Command/ChillImportUsersCommand.php @@ -335,7 +335,7 @@ class ChillImportUsersCommand extends Command protected function loadUsers() { - $reader = Reader::createFromPath($this->tempInput->getArgument('csvfile')); + $reader = Reader::from($this->tempInput->getArgument('csvfile')); $reader->setHeaderOffset(0); foreach ($reader->getRecords() as $line => $r) { @@ -363,7 +363,7 @@ class ChillImportUsersCommand extends Command protected function prepareGroupingCenters() { - $reader = Reader::createFromPath($this->tempInput->getOption('grouping-centers')); + $reader = Reader::from($this->tempInput->getOption('grouping-centers')); $reader->setHeaderOffset(0); foreach ($reader->getRecords() as $r) { @@ -379,7 +379,7 @@ class ChillImportUsersCommand extends Command protected function prepareWriter() { - $this->output = $output = Writer::createFromPath($this->tempInput + $this->output = $output = Writer::from($this->tempInput ->getOption('csv-dump'), 'a+'); $output->insertOne([ diff --git a/src/Bundle/ChillMainBundle/Command/ChillUserSendRenewPasswordCodeCommand.php b/src/Bundle/ChillMainBundle/Command/ChillUserSendRenewPasswordCodeCommand.php index 1951cdffa..eb3392bda 100644 --- a/src/Bundle/ChillMainBundle/Command/ChillUserSendRenewPasswordCodeCommand.php +++ b/src/Bundle/ChillMainBundle/Command/ChillUserSendRenewPasswordCodeCommand.php @@ -119,7 +119,7 @@ class ChillUserSendRenewPasswordCodeCommand extends Command protected function getReader() { try { - $reader = Reader::createFromPath($this->input->getArgument('csvfile')); + $reader = Reader::from($this->input->getArgument('csvfile')); } catch (\Exception $e) { $this->logger->error('The csv file could not be read', [ 'path' => $this->input->getArgument('csvfile'), diff --git a/src/Bundle/ChillMainBundle/Controller/UserExportController.php b/src/Bundle/ChillMainBundle/Controller/UserExportController.php index 2dc2556eb..d9369d9b9 100644 --- a/src/Bundle/ChillMainBundle/Controller/UserExportController.php +++ b/src/Bundle/ChillMainBundle/Controller/UserExportController.php @@ -42,7 +42,7 @@ final readonly class UserExportController $users = $this->userRepository->findAllAsArray($request->getLocale()); - $csv = Writer::createFromPath('php://temp', 'r+'); + $csv = Writer::from('php://temp', 'r+'); $csv->insertOne( array_map( fn (string $e) => $this->translator->trans('admin.users.export.'.$e), @@ -103,7 +103,7 @@ final readonly class UserExportController $userPermissions = $this->userRepository->findAllUserACLAsArray(); - $csv = Writer::createFromPath('php://temp', 'r+'); + $csv = Writer::from('php://temp', 'r+'); $csv->insertOne( array_map( fn (string $e) => $this->translator->trans('admin.users.export.'.$e), diff --git a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceBEFromBestAddress.php b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceBEFromBestAddress.php index fcf49079f..f8fc56f7a 100644 --- a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceBEFromBestAddress.php +++ b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceBEFromBestAddress.php @@ -64,7 +64,7 @@ class AddressReferenceBEFromBestAddress $uncompressedStream = gzopen($tmpname, 'r'); - $csv = Reader::createFromStream($uncompressedStream); + $csv = Reader::from($uncompressedStream); $csv->setDelimiter(','); $csv->setHeaderOffset(0); diff --git a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceBaseImporter.php b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceBaseImporter.php index adb49549b..b9ce839d3 100644 --- a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceBaseImporter.php +++ b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceBaseImporter.php @@ -287,7 +287,7 @@ final class AddressReferenceBaseImporter $filename = sprintf('%s-%s.csv', (new \DateTimeImmutable())->format('Ymd-His'), uniqid()); $path = Path::normalize(sprintf('%s%s%s', sys_get_temp_dir(), DIRECTORY_SEPARATOR, $filename)); - $writer = Writer::createFromPath($path, 'w+'); + $writer = Writer::from($path, 'w+'); // insert headers $writer->insertOne([ 'postalcode', diff --git a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceFromBAN.php b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceFromBAN.php index 1c03b7bfb..0aa4cd6ce 100644 --- a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceFromBAN.php +++ b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceFromBAN.php @@ -53,7 +53,7 @@ class AddressReferenceFromBAN // re-open it to read it $csvDecompressed = gzopen($path, 'r'); - $csv = Reader::createFromStream($csvDecompressed); + $csv = Reader::from($csvDecompressed); $csv->setDelimiter(';')->setHeaderOffset(0); $stmt = new Statement(); $stmt = $stmt->process($csv, [ diff --git a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceFromBano.php b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceFromBano.php index be20bbc11..6e7e693c8 100644 --- a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceFromBano.php +++ b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceFromBano.php @@ -41,7 +41,7 @@ class AddressReferenceFromBano fseek($file, 0); - $csv = Reader::createFromStream($file); + $csv = Reader::from($file); $csv->setDelimiter(','); $stmt = new Statement(); $stmt = $stmt->process($csv, [ diff --git a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceLU.php b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceLU.php index e1294732b..9c65e9367 100644 --- a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceLU.php +++ b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceLU.php @@ -39,7 +39,7 @@ class AddressReferenceLU fseek($file, 0); - $csv = Reader::createFromStream($file); + $csv = Reader::from($file); $csv->setDelimiter(';'); $csv->setHeaderOffset(0); diff --git a/src/Bundle/ChillMainBundle/Service/Import/PostalCodeBEFromBestAddress.php b/src/Bundle/ChillMainBundle/Service/Import/PostalCodeBEFromBestAddress.php index a95ba1abc..13b85b44a 100644 --- a/src/Bundle/ChillMainBundle/Service/Import/PostalCodeBEFromBestAddress.php +++ b/src/Bundle/ChillMainBundle/Service/Import/PostalCodeBEFromBestAddress.php @@ -43,7 +43,7 @@ class PostalCodeBEFromBestAddress $uncompressedStream = gzopen($tmpname, 'r'); - $csv = Reader::createFromStream($uncompressedStream); + $csv = Reader::from($uncompressedStream); $csv->setDelimiter(','); $csv->setHeaderOffset(0); diff --git a/src/Bundle/ChillMainBundle/Service/Import/PostalCodeFRFromOpenData.php b/src/Bundle/ChillMainBundle/Service/Import/PostalCodeFRFromOpenData.php index 8893181a8..1fa1de41b 100644 --- a/src/Bundle/ChillMainBundle/Service/Import/PostalCodeFRFromOpenData.php +++ b/src/Bundle/ChillMainBundle/Service/Import/PostalCodeFRFromOpenData.php @@ -47,7 +47,7 @@ class PostalCodeFRFromOpenData fseek($tmpfile, 0); - $csv = Reader::createFromStream($tmpfile); + $csv = Reader::from($tmpfile); $csv->setDelimiter(','); $csv->setHeaderOffset(0); diff --git a/src/Bundle/ChillPersonBundle/Command/ImportSocialWorkMetadata.php b/src/Bundle/ChillPersonBundle/Command/ImportSocialWorkMetadata.php index 249299888..98182abda 100644 --- a/src/Bundle/ChillPersonBundle/Command/ImportSocialWorkMetadata.php +++ b/src/Bundle/ChillPersonBundle/Command/ImportSocialWorkMetadata.php @@ -49,7 +49,7 @@ final class ImportSocialWorkMetadata extends Command $filepath = $input->getOption('filepath'); try { - $csv = Reader::createFromPath($filepath); + $csv = Reader::from($filepath); } catch (\Throwable $e) { throw new \Exception('Error while loading CSV.', 0, $e); } diff --git a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadSocialWorkMetadata.php b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadSocialWorkMetadata.php index 2c7e22b46..d6758eb8a 100644 --- a/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadSocialWorkMetadata.php +++ b/src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadSocialWorkMetadata.php @@ -29,7 +29,7 @@ class LoadSocialWorkMetadata extends Fixture implements OrderedFixtureInterface public function load(ObjectManager $manager): void { try { - $csv = Reader::createFromPath(__DIR__.'/data/social_work_metadata.csv'); + $csv = Reader::from(__DIR__.'/data/social_work_metadata.csv'); } catch (\Throwable $e) { throw new \Exception('Error while loading CSV.', 0, $e); } diff --git a/src/Bundle/ChillPersonBundle/Service/SocialWork/SocialActionCSVExportService.php b/src/Bundle/ChillPersonBundle/Service/SocialWork/SocialActionCSVExportService.php index d19b01382..09b4442b2 100644 --- a/src/Bundle/ChillPersonBundle/Service/SocialWork/SocialActionCSVExportService.php +++ b/src/Bundle/ChillPersonBundle/Service/SocialWork/SocialActionCSVExportService.php @@ -38,7 +38,7 @@ final readonly class SocialActionCSVExportService array_keys($this->formatRow(new SocialAction())) ); - $csv = Writer::createFromPath('php://temp', 'w+'); + $csv = Writer::from('php://temp', 'w+'); $csv->insertOne($headers); foreach ($actions as $action) { diff --git a/src/Bundle/ChillPersonBundle/Service/SocialWork/SocialIssueCSVExportService.php b/src/Bundle/ChillPersonBundle/Service/SocialWork/SocialIssueCSVExportService.php index ce403d192..8a3ba708f 100644 --- a/src/Bundle/ChillPersonBundle/Service/SocialWork/SocialIssueCSVExportService.php +++ b/src/Bundle/ChillPersonBundle/Service/SocialWork/SocialIssueCSVExportService.php @@ -36,7 +36,7 @@ readonly class SocialIssueCSVExportService public function generateCsv(array $issues): Writer { // CSV headers - $csv = Writer::createFromPath('php://temp', 'r+'); + $csv = Writer::from('php://temp', 'r+'); $csv->insertOne( array_map( fn (string $e) => $this->translator->trans($e), diff --git a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdpartyCSVExportController.php b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdpartyCSVExportController.php index 0ddc931a5..4a769b72f 100644 --- a/src/Bundle/ChillThirdPartyBundle/Controller/ThirdpartyCSVExportController.php +++ b/src/Bundle/ChillThirdPartyBundle/Controller/ThirdpartyCSVExportController.php @@ -51,7 +51,7 @@ class ThirdpartyCSVExportController extends AbstractController fwrite($output, "\xEF\xBB\xBF"); // Create CSV writer - $csv = Writer::createFromStream($output); + $csv = Writer::from($output); // Write header row $header = array_map(