28,6 → 28,7 |
// Paramètre de suivi et de pagination de l'API des obs PN |
protected $currentPage = ''; |
protected $currentProject = ''; |
protected $lastTimestamp = ''; |
protected $hasMore = false; |
|
// Traduction des organes de PN |
149,8 → 150,11 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
$reponse = curl_exec($ch); |
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
$temps = curl_getinfo($ch, CURLINFO_TOTAL_TIME); |
curl_close($ch); |
|
$this->debug('Temps total en secondes : '.$temps); |
|
// cool, maintenant on va trier ce qu'on a reçu |
if (!$reponse) { |
throw new Exception("\nPN ne répond rien à l'adresse {$this->currentPage}\n"); |
168,8 → 172,16 |
$observations_PN = $responseJson['data'] ?? []; |
|
$this->hasMore = $responseJson['hasMore']; |
$this->lastTimestamp = end($observations_PN)['dateUpdated']; |
if ($this->hasMore) { |
$this->currentPage = Config::get('urlPlantnetBase').$responseJson['next']; |
// $url_service = Config::get('urlPlantnetBase').$responseJson['next']; |
// Build next page url with last read timestamp, to avoid pagination latency |
$url_service = str_replace( |
['{project}', '{token}', '{startDate}', '{lifecycle}'], |
[$project['id'], Config::get('tokenPlantnet'), $this->lastTimestamp, $lifecycle], |
Config::get('urlPlantnetBase').Config::get('urlPlantnetLatestChanges') |
); |
$this->currentPage = $url_service; |
$this->debug("URL service derniers changements, page suivante : {$this->currentPage}"); |
} else { |
$this->currentPage = ''; |
211,12 → 223,12 |
|
foreach ($observations_PN as $obs) { |
// est-ce qu'on a déjà traité cette obs ? (oui une même obs peut être dans plusieurs projects) |
if (in_array($obs['id'], $this->processedObsId)) { |
if (array_key_exists($obs['id'], $this->processedObsId)) { |
$this->log("Obs {$obs['id']} déjà traitée pendant cette run"); |
continue; |
} else { |
$this->processedObsId[] = $obs['id']; |
$this->log("Obs {$obs['id']} ajoutée à la liste de cette run"); |
$this->processedObsId[$obs['id']] = true; |
$this->log("Obs {$obs['id']} ajoutée à la liste des obs traitées pendant cette run"); |
} |
|
// on ne teste pas la suppression de l'obs ici, faut le faire après avoir vérifié si on l'a déjà synchro |