diff --git a/src/Bundle/ChillMainBundle/Command/LoadAddressReferenceCommand.php b/src/Bundle/ChillMainBundle/Command/LoadAddressReferenceCommand.php index 650bc6c66..e14851191 100644 --- a/src/Bundle/ChillMainBundle/Command/LoadAddressReferenceCommand.php +++ b/src/Bundle/ChillMainBundle/Command/LoadAddressReferenceCommand.php @@ -48,7 +48,7 @@ class LoadAddressReferenceCommand extends Command { $this ->setName('chill:main:address-reference:populate') - ->setDescription('Load or update countries in db. This command does not delete or update existing address reference,'. + ->setDescription('Load or update reference addresses in db. This command does not delete or update existing address reference,'. 'but will add new address reference entities based on their timestamp'); } @@ -60,30 +60,39 @@ class LoadAddressReferenceCommand extends Command { $maxCount = $this->countWFSFeatures($this->wfsBaseUrl, $output); + $output->writeln('Number of addresses to be fetched: ' . $maxCount); $totalCount = 0; $batchSize = 100; + $success = 0; $em = $this->entityManager; while($totalCount < $maxCount) { try { $addressReferenceArray = $this->fetchWFS($totalCount, $batchSize, $output); + $success = $success + 1; + + foreach($addressReferenceArray as $a) { + if (static::isAddressReferenceNew($a)) { + $em->persist($a); + } + } + + $em->flush(); + $em->clear(); + } catch (\Exception $ex) { $output->writeln('Cannot fetch WFS. Error message is: '.$ex->getMessage().''); } - foreach($addressReferenceArray as $a) { - if (static::isAddressReferenceNew($a)) { - $em->persist($a); - } - } - - $em->flush(); - $totalCount = $totalCount + $batchSize; } + $em->flush(); + + $output->writeln($success * $batchSize . '/'. $maxCount . 'reference address were loaded in the database.'); + return 0; } @@ -127,6 +136,7 @@ class LoadAddressReferenceCommand extends Command $wfsBaseUrl = $this->wfsBaseUrl; $wfsUrl = $wfsBaseUrl . '&startIndex=' . $startIndex . '&count=' . $count . '&OUTPUTFORMAT=geojson'; + $output->writeln('Start fetching WFS data @: ' . $wfsUrl); try { $response = $this->client->request('GET', $wfsUrl);