22,12 → 22,8 |
// Cache d'informations utilisateurs provenant de l'annuaire TB |
protected $userInfos = []; |
|
// Cache des obs id PN traitées pendant cette run |
protected $processedObsId = []; |
|
// Paramètre de suivi et de pagination de l'API des obs PN |
protected $currentPage = ''; |
protected $currentProject = ''; |
protected $lastTimestamp = ''; |
protected $hasMore = false; |
|
112,32 → 108,25 |
|
/** |
* Considering all modified pn obs since startDate |
* One pn project after an other |
* Inserting obs in tb db (if new and matching user email) |
*/ |
private function updateLatest(string $startDate = '1917:03:15 00:00:00', string $lifecycle = 'modified') { |
$startDate = strtotime($startDate) * 1000; // we need a microtimestamp |
|
$pnProjects = $this->getProjects(); // refresh projects list |
foreach ($pnProjects as $project) { |
do { |
$observations_PN = $this->getProjectLatest($project, $startDate, $lifecycle); |
$this->updateObs($observations_PN); |
} while ($this->hasMore); |
} |
do { |
$observations_PN = $this->getLatest($startDate, $lifecycle); |
$this->updateObs($observations_PN); |
} while ($this->hasMore); |
} |
|
private function getProjectLatest(array $project, int $startDate, string $lifecycle): array { |
$this->currentProject = $project; |
private function getLatest(int $startDate, string $lifecycle): array { |
$this->refreshBddConnexion(); |
|
if (!$this->currentPage) { |
echo 'Projet ' . $project['name'] . "\n"; |
|
// hop, on appelle le service de PN |
$url_service = str_replace( |
['{project}', '{token}', '{startDate}', '{lifecycle}'], |
[$project['id'], Config::get('tokenPlantnet'), $startDate, $lifecycle], |
['{token}', '{startDate}', '{lifecycle}'], |
[Config::get('tokenPlantnet'), $startDate, $lifecycle], |
Config::get('urlPlantnetBase').Config::get('urlPlantnetLatestChanges') |
); |
|
177,8 → 166,8 |
// $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], |
['{token}', '{startDate}', '{lifecycle}'], |
[Config::get('tokenPlantnet'), $this->lastTimestamp, $lifecycle], |
Config::get('urlPlantnetBase').Config::get('urlPlantnetLatestChanges') |
); |
$this->currentPage = $url_service; |
191,7 → 180,7 |
} |
|
private function getProjects(): array { |
// get PN projects list |
// get PN projects list (useless since we have a single source) |
$url = str_replace('{token}', Config::get('tokenPlantnet'), Config::get('urlPlantnetBase').Config::get('urlPlantnetProjects')); |
|
$this->debug("URL service liste projets : $url"); |
222,15 → 211,6 |
$url_cel_widget_saisie = Config::get('urlCelWidgetSaisie'); |
|
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 (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']] = 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 |
if (!isset($obs['currentName'])) { |
$this->log("Obs {$obs['id']} sans nom de taxon, on zap"); |
387,12 → 367,12 |
// 'obsId1[num_nom_ret]' => '', |
// 'obsId1[num_nom_sel]' => '', |
// 'obsId1[num_taxon]' => '', |
'obsId1[referentiel]' => $this->findProbableTaxoRepos($this->currentProject['id']), // @TODO faire une fois et mettre en cache |
'obsId1[referentiel]' => $this->findProbableTaxoRepos($obs['project']), // @TODO faire une fois et mettre en cache |
// 'obsId1[station]' => '', |
'obsId1[obs_id]' => $obs['id'], |
'projet' => 'PlantNet', |
'tag-img' => implode(', ', $tags_images ?? []), |
'tag-obs' => 'plantnet, plantnet-mobile, pn:referentiel-' . $this->currentProject['id'], |
'tag-obs' => 'plantnet, plantnet-mobile, pn:referentiel-' . $obs['project'], |
'utilisateur[courriel]' => $email, |
'utilisateur[id_utilisateur]' => $infos_utilisateur['id'], |
'utilisateur[nom]' => $infos_utilisateur['nom'], |
654,7 → 634,6 |
|
private function updateOnePN($pnObsId, $pnProjectId) { |
if (!is_int($pnObsId) || !is_string($pnProjectId)) { |
die(var_dump($pnObsId, $pnProjectId)); |
throw new Exception("\nBad params types, give me an integer and a string plz\n"); |
} |
// get PN project list |
671,11 → 650,6 |
echo " - $projectId ($projectName)\n"; |
} |
throw new Exception("Project $pnProjectId does not exist\n"); |
} else { |
$this->currentProject = [ |
'id' => $pnProjectId, |
'name' => $list[$pnProjectId], |
]; |
} |
|
// get PN obs |