mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
address: improve load addresse reference command"
This commit is contained in:
parent
65859f62f3
commit
1b1eb45d15
@ -48,7 +48,7 @@ class LoadAddressReferenceCommand extends Command
|
|||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
->setName('chill:main:address-reference:populate')
|
->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');
|
'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);
|
$maxCount = $this->countWFSFeatures($this->wfsBaseUrl, $output);
|
||||||
|
$output->writeln('Number of addresses to be fetched: ' . $maxCount);
|
||||||
$totalCount = 0;
|
$totalCount = 0;
|
||||||
$batchSize = 100;
|
$batchSize = 100;
|
||||||
|
|
||||||
|
$success = 0;
|
||||||
$em = $this->entityManager;
|
$em = $this->entityManager;
|
||||||
|
|
||||||
while($totalCount < $maxCount) {
|
while($totalCount < $maxCount) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$addressReferenceArray = $this->fetchWFS($totalCount, $batchSize, $output);
|
$addressReferenceArray = $this->fetchWFS($totalCount, $batchSize, $output);
|
||||||
} catch (\Exception $ex) {
|
$success = $success + 1;
|
||||||
$output->writeln('<warning>Cannot fetch WFS. Error message is: '.$ex->getMessage().'</warning>');
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($addressReferenceArray as $a) {
|
foreach($addressReferenceArray as $a) {
|
||||||
if (static::isAddressReferenceNew($a)) {
|
if (static::isAddressReferenceNew($a)) {
|
||||||
@ -80,10 +80,19 @@ class LoadAddressReferenceCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
$em->clear();
|
||||||
|
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
$output->writeln('<warning>Cannot fetch WFS. Error message is: '.$ex->getMessage().'</warning>');
|
||||||
|
}
|
||||||
|
|
||||||
$totalCount = $totalCount + $batchSize;
|
$totalCount = $totalCount + $batchSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
$output->writeln($success * $batchSize . '/'. $maxCount . 'reference address were loaded in the database.');
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,6 +136,7 @@ class LoadAddressReferenceCommand extends Command
|
|||||||
|
|
||||||
$wfsBaseUrl = $this->wfsBaseUrl;
|
$wfsBaseUrl = $this->wfsBaseUrl;
|
||||||
$wfsUrl = $wfsBaseUrl . '&startIndex=' . $startIndex . '&count=' . $count . '&OUTPUTFORMAT=geojson';
|
$wfsUrl = $wfsBaseUrl . '&startIndex=' . $startIndex . '&count=' . $count . '&OUTPUTFORMAT=geojson';
|
||||||
|
$output->writeln('Start fetching WFS data @: ' . $wfsUrl);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->client->request('GET', $wfsUrl);
|
$response = $this->client->request('GET', $wfsUrl);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user