From 3770318e6a43769110a7f49af2164cb8167649c7 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 6 Oct 2021 21:48:56 +0200 Subject: [PATCH] enlarge the loadpostalcode command to more fields --- .../Command/LoadPostalCodesCommand.php | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Command/LoadPostalCodesCommand.php b/src/Bundle/ChillMainBundle/Command/LoadPostalCodesCommand.php index ba51db779..6b047a04b 100644 --- a/src/Bundle/ChillMainBundle/Command/LoadPostalCodesCommand.php +++ b/src/Bundle/ChillMainBundle/Command/LoadPostalCodesCommand.php @@ -19,6 +19,8 @@ namespace Chill\MainBundle\Command; +use Chill\MainBundle\Doctrine\Model\Point; +use Chill\MainBundle\Entity\Country; use Doctrine\ORM\EntityManager; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -69,6 +71,9 @@ class LoadPostalCodesCommand extends Command . "using the postal code and name. \n" . "The CSV file must have the following columns: " . "postal code, label, country code." + . "Optionally, the csv file can have the following " + . "columns after the country code: reference code, latitude, longitude, source. " + . "The latitude and longitude columns are supposed to be in WGS84 and expressed in decimal degrees. " . "The CSV file should not have any header row.") ->addArgument('csv_file', InputArgument::REQUIRED, "the path to " . "the csv file. See the help for specifications.") @@ -137,7 +142,7 @@ class LoadPostalCodesCommand extends Command $output->writeln(''.$num.' were added !'); } - private function getCSVResource(InputInterface $input) + public function getCSVResource(InputInterface $input) { $fs = new Filesystem(); $filename = $input->getArgument('csv_file'); @@ -163,7 +168,7 @@ class LoadPostalCodesCommand extends Command } $em = $this->entityManager; $country = $em - ->getRepository('ChillMainBundle:Country') + ->getRepository(Country::class) ->findOneBy(array('countryCode' => $row[2])); if ($country === NULL) { @@ -173,7 +178,7 @@ class LoadPostalCodesCommand extends Command // try to find an existing postal code $existingPC = $em - ->getRepository('ChillMainBundle:PostalCode') + ->getRepository(PostalCode::class) ->findBy(array('code' => $row[0], 'name' => $row[1])); if (count($existingPC) > 0) { @@ -187,6 +192,18 @@ class LoadPostalCodesCommand extends Command ->setCountry($country) ; + if (NULL != $row[3]){ + $postalCode->setRefId($row[3]); + } + + if (NULL != $row[4] & NULL != $row[5]){ + $postalCode->setCenter(Point::fromLonLat((float) $row[5], (float) $row[4])); + } + + if (NULL != $row[6]){ + $postalCode->setSource($row[6]); + } + $errors = $this->validator->validate($postalCode); if ($errors->count() == 0) {