| Line 20... |
Line 20... |
| 20 |
protected $correspondingIdsFilename = '';
|
20 |
protected $correspondingIdsFilename = '';
|
| Line 21... |
Line 21... |
| 21 |
|
21 |
|
| 22 |
// Cache d'informations utilisateurs provenant de l'annuaire TB
|
22 |
// Cache d'informations utilisateurs provenant de l'annuaire TB
|
| Line 23... |
Line -... |
| 23 |
protected $userInfos = [];
|
- |
|
| 24 |
|
- |
|
| 25 |
// Cache des obs id PN traitées pendant cette run
|
- |
|
| 26 |
protected $processedObsId = [];
|
23 |
protected $userInfos = [];
|
| 27 |
|
24 |
|
| 28 |
// Paramètre de suivi et de pagination de l'API des obs PN
|
- |
|
| 29 |
protected $currentPage = '';
|
25 |
// Paramètre de suivi et de pagination de l'API des obs PN
|
| 30 |
protected $currentProject = '';
|
26 |
protected $currentPage = '';
|
| Line 31... |
Line 27... |
| 31 |
protected $lastTimestamp = '';
|
27 |
protected $lastTimestamp = '';
|
| 32 |
protected $hasMore = false;
|
28 |
protected $hasMore = false;
|
| Line 110... |
Line 106... |
| 110 |
}
|
106 |
}
|
| 111 |
}
|
107 |
}
|
| Line 112... |
Line 108... |
| 112 |
|
108 |
|
| 113 |
/**
|
109 |
/**
|
| 114 |
* Considering all modified pn obs since startDate
|
- |
|
| 115 |
* One pn project after an other
|
110 |
* Considering all modified pn obs since startDate
|
| 116 |
* Inserting obs in tb db (if new and matching user email)
|
111 |
* Inserting obs in tb db (if new and matching user email)
|
| 117 |
*/
|
112 |
*/
|
| 118 |
private function updateLatest(string $startDate = '1917:03:15 00:00:00', string $lifecycle = 'modified') {
|
113 |
private function updateLatest(string $startDate = '1917:03:15 00:00:00', string $lifecycle = 'modified') {
|
| Line 119... |
Line -... |
| 119 |
$startDate = strtotime($startDate) * 1000; // we need a microtimestamp
|
- |
|
| 120 |
|
- |
|
| 121 |
$pnProjects = $this->getProjects(); // refresh projects list
|
114 |
$startDate = strtotime($startDate) * 1000; // we need a microtimestamp
|
| 122 |
foreach ($pnProjects as $project) {
|
115 |
|
| 123 |
do {
|
116 |
do {
|
| 124 |
$observations_PN = $this->getProjectLatest($project, $startDate, $lifecycle);
|
117 |
$observations_PN = $this->getLatest($startDate, $lifecycle);
|
| 125 |
$this->updateObs($observations_PN);
|
- |
|
| 126 |
} while ($this->hasMore);
|
118 |
$this->updateObs($observations_PN);
|
| Line 127... |
Line 119... |
| 127 |
}
|
119 |
} while ($this->hasMore);
|
| 128 |
}
|
- |
|
| 129 |
|
120 |
}
|
| Line 130... |
Line 121... |
| 130 |
private function getProjectLatest(array $project, int $startDate, string $lifecycle): array {
|
121 |
|
| 131 |
$this->currentProject = $project;
|
- |
|
| 132 |
$this->refreshBddConnexion();
|
- |
|
| 133 |
|
122 |
private function getLatest(int $startDate, string $lifecycle): array {
|
| 134 |
if (!$this->currentPage) {
|
123 |
$this->refreshBddConnexion();
|
| 135 |
echo 'Projet ' . $project['name'] . "\n";
|
124 |
|
| 136 |
|
125 |
if (!$this->currentPage) {
|
| 137 |
// hop, on appelle le service de PN
|
126 |
// hop, on appelle le service de PN
|
| 138 |
$url_service = str_replace(
|
127 |
$url_service = str_replace(
|
| Line 139... |
Line 128... |
| 139 |
['{project}', '{token}', '{startDate}', '{lifecycle}'],
|
128 |
['{token}', '{startDate}', '{lifecycle}'],
|
| Line 175... |
Line 164... |
| 175 |
$this->lastTimestamp = end($observations_PN)['dateUpdated'];
|
164 |
$this->lastTimestamp = end($observations_PN)['dateUpdated'];
|
| 176 |
if ($this->hasMore) {
|
165 |
if ($this->hasMore) {
|
| 177 |
// $url_service = Config::get('urlPlantnetBase').$responseJson['next'];
|
166 |
// $url_service = Config::get('urlPlantnetBase').$responseJson['next'];
|
| 178 |
// Build next page url with last read timestamp, to avoid pagination latency
|
167 |
// Build next page url with last read timestamp, to avoid pagination latency
|
| 179 |
$url_service = str_replace(
|
168 |
$url_service = str_replace(
|
| 180 |
['{project}', '{token}', '{startDate}', '{lifecycle}'],
|
169 |
['{token}', '{startDate}', '{lifecycle}'],
|
| 181 |
[$project['id'], Config::get('tokenPlantnet'), $this->lastTimestamp, $lifecycle],
|
170 |
[Config::get('tokenPlantnet'), $this->lastTimestamp, $lifecycle],
|
| 182 |
Config::get('urlPlantnetBase').Config::get('urlPlantnetLatestChanges')
|
171 |
Config::get('urlPlantnetBase').Config::get('urlPlantnetLatestChanges')
|
| 183 |
);
|
172 |
);
|
| 184 |
$this->currentPage = $url_service;
|
173 |
$this->currentPage = $url_service;
|
| 185 |
$this->debug("URL service derniers changements, page suivante : {$this->currentPage}");
|
174 |
$this->debug("URL service derniers changements, page suivante : {$this->currentPage}");
|
| 186 |
} else {
|
175 |
} else {
|
| Line 189... |
Line 178... |
| 189 |
|
178 |
|
| 190 |
return $observations_PN;
|
179 |
return $observations_PN;
|
| Line 191... |
Line 180... |
| 191 |
}
|
180 |
}
|
| 192 |
|
181 |
|
| 193 |
private function getProjects(): array {
|
182 |
private function getProjects(): array {
|
| Line 194... |
Line 183... |
| 194 |
// get PN projects list
|
183 |
// get PN projects list (useless since we have a single source)
|
| Line 195... |
Line 184... |
| 195 |
$url = str_replace('{token}', Config::get('tokenPlantnet'), Config::get('urlPlantnetBase').Config::get('urlPlantnetProjects'));
|
184 |
$url = str_replace('{token}', Config::get('tokenPlantnet'), Config::get('urlPlantnetBase').Config::get('urlPlantnetProjects'));
|
| Line 220... |
Line 209... |
| 220 |
private function updateObs(array $observations_PN) {
|
209 |
private function updateObs(array $observations_PN) {
|
| Line 221... |
Line 210... |
| 221 |
|
210 |
|
| Line 222... |
Line 211... |
| 222 |
$url_cel_widget_saisie = Config::get('urlCelWidgetSaisie');
|
211 |
$url_cel_widget_saisie = Config::get('urlCelWidgetSaisie');
|
| 223 |
|
- |
|
| 224 |
foreach ($observations_PN as $obs) {
|
- |
|
| 225 |
// est-ce qu'on a déjà traité cette obs ? (oui une même obs peut être dans plusieurs projects)
|
- |
|
| 226 |
if (array_key_exists($obs['id'], $this->processedObsId)) {
|
- |
|
| 227 |
$this->log("Obs {$obs['id']} déjà traitée pendant cette run");
|
- |
|
| 228 |
continue;
|
- |
|
| 229 |
} else {
|
- |
|
| 230 |
$this->processedObsId[$obs['id']] = true;
|
- |
|
| 231 |
$this->log("Obs {$obs['id']} ajoutée à la liste des obs traitées pendant cette run");
|
- |
|
| 232 |
}
|
212 |
|
| 233 |
|
213 |
foreach ($observations_PN as $obs) {
|
| 234 |
// 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
|
214 |
// 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
|
| 235 |
if (!isset($obs['currentName'])) {
|
215 |
if (!isset($obs['currentName'])) {
|
| 236 |
$this->log("Obs {$obs['id']} sans nom de taxon, on zap");
|
216 |
$this->log("Obs {$obs['id']} sans nom de taxon, on zap");
|
| Line 385... |
Line 365... |
| 385 |
'obsId1[certitude]' => 'douteux',
|
365 |
'obsId1[certitude]' => 'douteux',
|
| 386 |
// 'obsId1[notes]' => '',
|
366 |
// 'obsId1[notes]' => '',
|
| 387 |
// 'obsId1[num_nom_ret]' => '',
|
367 |
// 'obsId1[num_nom_ret]' => '',
|
| 388 |
// 'obsId1[num_nom_sel]' => '',
|
368 |
// 'obsId1[num_nom_sel]' => '',
|
| 389 |
// 'obsId1[num_taxon]' => '',
|
369 |
// 'obsId1[num_taxon]' => '',
|
| 390 |
'obsId1[referentiel]' => $this->findProbableTaxoRepos($this->currentProject['id']), // @TODO faire une fois et mettre en cache
|
370 |
'obsId1[referentiel]' => $this->findProbableTaxoRepos($obs['project']), // @TODO faire une fois et mettre en cache
|
| 391 |
// 'obsId1[station]' => '',
|
371 |
// 'obsId1[station]' => '',
|
| 392 |
'obsId1[obs_id]' => $obs['id'],
|
372 |
'obsId1[obs_id]' => $obs['id'],
|
| 393 |
'projet' => 'PlantNet',
|
373 |
'projet' => 'PlantNet',
|
| 394 |
'tag-img' => implode(', ', $tags_images ?? []),
|
374 |
'tag-img' => implode(', ', $tags_images ?? []),
|
| 395 |
'tag-obs' => 'plantnet, plantnet-mobile, pn:referentiel-' . $this->currentProject['id'],
|
375 |
'tag-obs' => 'plantnet, plantnet-mobile, pn:referentiel-' . $obs['project'],
|
| 396 |
'utilisateur[courriel]' => $email,
|
376 |
'utilisateur[courriel]' => $email,
|
| 397 |
'utilisateur[id_utilisateur]' => $infos_utilisateur['id'],
|
377 |
'utilisateur[id_utilisateur]' => $infos_utilisateur['id'],
|
| 398 |
'utilisateur[nom]' => $infos_utilisateur['nom'],
|
378 |
'utilisateur[nom]' => $infos_utilisateur['nom'],
|
| 399 |
'utilisateur[prenom]' => $infos_utilisateur['prenom'],
|
379 |
'utilisateur[prenom]' => $infos_utilisateur['prenom'],
|
| 400 |
'origin' => 'pullPlantnet',
|
380 |
'origin' => 'pullPlantnet',
|
| Line 652... |
Line 632... |
| 652 |
// // insert_new_votes($pn_sorted_votes, $existing_votes);
|
632 |
// // insert_new_votes($pn_sorted_votes, $existing_votes);
|
| 653 |
}
|
633 |
}
|
| Line 654... |
Line 634... |
| 654 |
|
634 |
|
| 655 |
private function updateOnePN($pnObsId, $pnProjectId) {
|
635 |
private function updateOnePN($pnObsId, $pnProjectId) {
|
| 656 |
if (!is_int($pnObsId) || !is_string($pnProjectId)) {
|
- |
|
| 657 |
die(var_dump($pnObsId, $pnProjectId));
|
636 |
if (!is_int($pnObsId) || !is_string($pnProjectId)) {
|
| 658 |
throw new Exception("\nBad params types, give me an integer and a string plz\n");
|
637 |
throw new Exception("\nBad params types, give me an integer and a string plz\n");
|
| 659 |
}
|
638 |
}
|
| 660 |
// get PN project list
|
639 |
// get PN project list
|
| 661 |
$list = [];
|
640 |
$list = [];
|
| Line 669... |
Line 648... |
| 669 |
echo "Available projects:\n";
|
648 |
echo "Available projects:\n";
|
| 670 |
foreach ($list as $projectId => $projectName) {
|
649 |
foreach ($list as $projectId => $projectName) {
|
| 671 |
echo " - $projectId ($projectName)\n";
|
650 |
echo " - $projectId ($projectName)\n";
|
| 672 |
}
|
651 |
}
|
| 673 |
throw new Exception("Project $pnProjectId does not exist\n");
|
652 |
throw new Exception("Project $pnProjectId does not exist\n");
|
| 674 |
} else {
|
- |
|
| 675 |
$this->currentProject = [
|
- |
|
| 676 |
'id' => $pnProjectId,
|
- |
|
| 677 |
'name' => $list[$pnProjectId],
|
- |
|
| 678 |
];
|
- |
|
| 679 |
}
|
653 |
}
|
| Line 680... |
Line 654... |
| 680 |
|
654 |
|
| 681 |
// get PN obs
|
655 |
// get PN obs
|
| 682 |
$urlInfosObs = str_replace(
|
656 |
$urlInfosObs = str_replace(
|