address: improve load addresse reference command"

This commit is contained in:
nobohan 2021-05-20 15:44:04 +02:00
parent 65859f62f3
commit 1b1eb45d15

View File

@ -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,18 +60,18 @@ 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);
} catch (\Exception $ex) {
$output->writeln('<warning>Cannot fetch WFS. Error message is: '.$ex->getMessage().'</warning>');
}
$success = $success + 1;
foreach($addressReferenceArray as $a) {
if (static::isAddressReferenceNew($a)) {
@ -80,10 +80,19 @@ class LoadAddressReferenceCommand extends Command
}
$em->flush();
$em->clear();
} catch (\Exception $ex) {
$output->writeln('<warning>Cannot fetch WFS. Error message is: '.$ex->getMessage().'</warning>');
}
$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);