From 9c28df25a1b32499eec56acb4200ac9eb160effe Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 28 Jun 2024 10:45:58 +0200 Subject: [PATCH] DX: Improve Lux adress import command + register in config --- .../Service/Import/AddressReferenceLU.php | 14 +++++--------- .../ChillMainBundle/config/services/command.yaml | 6 ++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceLU.php b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceLU.php index f5cb03f19..d70b5085d 100644 --- a/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceLU.php +++ b/src/Bundle/ChillMainBundle/Service/Import/AddressReferenceLU.php @@ -33,16 +33,13 @@ class AddressReferenceLU throw new \Exception('Could not download CSV: '.$response->getStatusCode()); } - $tmpname = tempnam(sys_get_temp_dir(), 'php-add-'); - $file = fopen($tmpname, 'r+b'); + $file = tmpfile(); foreach ($this->client->stream($response) as $chunk) { fwrite($file, $chunk->getContent()); } - fclose($file); - - //$uncompressedStream = gzopen($tmpname, 'r'); + fseek($file, 0); $csv = Reader::createFromStream($file); $csv->setDelimiter(';'); @@ -54,7 +51,7 @@ class AddressReferenceLU $this->addressToReferenceMatcher->checkAddressesMatchingReferences(); - //gzclose($uncompressedStream); + fclose($file); } private function process_address(Reader $csv): void @@ -82,14 +79,13 @@ class AddressReferenceLU $stmt = Statement::create()->process($csv); $arr_postal_codes = []; foreach ($stmt as $record) { - //if (false === \in_array($record['code_postal'], $arr_postal_codes, true)) { - if (false === \array_key_exists($record['code_postal'], $arr_postal_codes, true)) { + if (false === \array_key_exists($record['code_postal'], $arr_postal_codes)) { $this->postalCodeBaseImporter->importCode( 'LU', trim((string) $record['localite']), trim((string) $record['code_postal']), trim((string) $record['code_postal']), - 'bd addresses', + 'bd-addresses.lux', (float) $record['lat_wgs84'], (float) $record['lon_wgs84'], 4326 diff --git a/src/Bundle/ChillMainBundle/config/services/command.yaml b/src/Bundle/ChillMainBundle/config/services/command.yaml index 8a2327c0b..94cb2cf97 100644 --- a/src/Bundle/ChillMainBundle/config/services/command.yaml +++ b/src/Bundle/ChillMainBundle/config/services/command.yaml @@ -59,6 +59,12 @@ services: tags: - { name: console.command } + Chill\MainBundle\Command\LoadAddressesLUFromBDAddressCommand: + autoconfigure: true + autowire: true + tags: + - { name: console.command } + Chill\MainBundle\Command\ExecuteCronJobCommand: autoconfigure: true autowire: true