| Line 52... |
Line 52... |
| 52 |
* @var array
|
52 |
* @var array
|
| 53 |
*/
|
53 |
*/
|
| 54 |
protected $parametres_autorises = array(
|
54 |
protected $parametres_autorises = array(
|
| 55 |
'-startDate' => array(false, '1', 'Date de début (parsée par strtotime). Ex: "YYYY:MM:DD HH:II:SS"'),
|
55 |
'-startDate' => array(false, '1', 'Date de début (parsée par strtotime). Ex: "YYYY:MM:DD HH:II:SS"'),
|
| 56 |
'-pnObsId' => array(false, true, "ID de l'obs chez PlantNet"),
|
56 |
'-pnObsId' => array(false, true, "ID de l'obs chez PlantNet"),
|
| - |
|
57 |
'-project' => array(false, true, "projectId de l'obs chez PlantNet"),
|
| 57 |
'-tbObsId' => array(false, true, "ID de l'obs chez Tela"),
|
58 |
'-tbObsId' => array(false, true, "ID de l'obs chez Tela"),
|
| 58 |
);
|
59 |
);
|
| Line 59... |
Line 60... |
| 59 |
|
60 |
|
| 60 |
public function __construct($script_nom, $parametres_cli) {
|
61 |
public function __construct($script_nom, $parametres_cli) {
|
| Line 70... |
Line 71... |
| 70 |
switch ($cmd) {
|
71 |
switch ($cmd) {
|
| 71 |
case 'updateLatest':
|
72 |
case 'updateLatest':
|
| 72 |
$this->updateLatest($this->getParametre('startDate'));
|
73 |
$this->updateLatest($this->getParametre('startDate'));
|
| 73 |
break;
|
74 |
break;
|
| 74 |
case 'updateOnePN':
|
75 |
case 'updateOnePN':
|
| 75 |
$this->updateOne($this->getParametre('pnObsId'));
|
76 |
$this->updateOnePN((int)$this->getParametre('pnObsId'), $this->getParametre('project'));
|
| 76 |
break;
|
77 |
break;
|
| 77 |
case 'updateOneTB':
|
78 |
case 'updateOneTB':
|
| 78 |
$this->updateOneTB($this->getParametre('tbObsId'));
|
79 |
$this->updateOneTB($this->getParametre('tbObsId'));
|
| 79 |
break;
|
80 |
break;
|
| 80 |
case 'updateCorrespondingIdsTable':
|
81 |
case 'updateCorrespondingIdsTable':
|
| Line 82... |
Line 83... |
| 82 |
break;
|
83 |
break;
|
| 83 |
default:
|
84 |
default:
|
| 84 |
$msg = "Erreur : la commande '$cmd' n'existe pas!\n"
|
85 |
$msg = "Erreur : la commande '$cmd' n'existe pas!\n"
|
| 85 |
. ', utilisez plutôt :' . "\n"
|
86 |
. ', utilisez plutôt :' . "\n"
|
| 86 |
. 'php cli.php PullPlantnet -a updateLatest -startDate "YYYY:MM:DD HH:II:SS"' . "\n"
|
87 |
. 'php cli.php PullPlantnet -a updateLatest -startDate "YYYY:MM:DD HH:II:SS"' . "\n"
|
| 87 |
. 'php cli.php PullPlantnet -a updateOnePN -pnObsId "xxxxxx"' . "\n"
|
88 |
. 'php cli.php PullPlantnet -a updateOnePN -pnObsId "xxxxxx" -project "xxxxxx"' . "\n"
|
| 88 |
. 'php cli.php PullPlantnet -a updateOneTB -tbObsId "xxxxxx"' . "\n"
|
89 |
. 'php cli.php PullPlantnet -a updateOneTB -tbObsId "xxxxxx"' . "\n"
|
| 89 |
. 'php cli.php PullPlantnet -a updateCorrespondingIdsTable' . "\n"
|
90 |
. 'php cli.php PullPlantnet -a updateCorrespondingIdsTable' . "\n"
|
| 90 |
;
|
91 |
;
|
| 91 |
throw new Exception($msg);
|
92 |
throw new Exception($msg);
|
| 92 |
}
|
93 |
}
|
| Line 147... |
Line 148... |
| 147 |
$observations_PN = $responseJson['data'] ?? [];
|
148 |
$observations_PN = $responseJson['data'] ?? [];
|
| Line 148... |
Line 149... |
| 148 |
|
149 |
|
| 149 |
$this->hasMore = $responseJson['hasMore'];
|
150 |
$this->hasMore = $responseJson['hasMore'];
|
| 150 |
if ($this->hasMore) {
|
151 |
if ($this->hasMore) {
|
| 151 |
$this->count += count($observations_PN);
|
152 |
$this->count += count($observations_PN);
|
| 152 |
$this->currentPage = Config::get('urlPlantnetBase').$responseJson['next'].$this->count;
|
153 |
$this->currentPage = Config::get('urlPlantnetBase').$responseJson['next'];
|
| 153 |
} else {
|
154 |
} else {
|
| 154 |
$this->currentPage = '';
|
155 |
$this->currentPage = '';
|
| 155 |
$this->count = 0;
|
156 |
$this->count = 0;
|
| Line 218... |
Line 219... |
| 218 |
$email = $obs['author']['email'];
|
219 |
$email = $obs['author']['email'];
|
| 219 |
$infos_utilisateur = $this->findUserInfo($email);
|
220 |
$infos_utilisateur = $this->findUserInfo($email);
|
| 220 |
if (!$infos_utilisateur) {
|
221 |
if (!$infos_utilisateur) {
|
| 221 |
continue; // c'est pas un telabotaniste
|
222 |
continue; // c'est pas un telabotaniste
|
| 222 |
}
|
223 |
}
|
| 223 |
echo "Synchro d'une obs d'un telabotaniste : $email\n";
|
224 |
//echo "Synchro d'une obs d'un telabotaniste : $email";
|
| 224 |
// echo json_encode($obs);
|
225 |
// echo json_encode($obs);
|
| 225 |
// die(var_dump($obs));
|
226 |
// die(var_dump($obs));
|
| Line 226... |
Line 227... |
| 226 |
|
227 |
|
| 227 |
// vérification que l'obs n'a pas déjà été ajoutée à la BdD de Tela
|
228 |
// vérification que l'obs n'a pas déjà été ajoutée à la BdD de Tela
|
| Line 232... |
Line 233... |
| 232 |
if ($res) {
|
233 |
if ($res) {
|
| 233 |
// l'obs existe déjà, on vérifie si il faut màj puis on passe à la suite
|
234 |
// l'obs existe déjà, on vérifie si il faut màj puis on passe à la suite
|
| 234 |
// la date de l'obs est un microtime, donc on coupe les millièmes
|
235 |
// la date de l'obs est un microtime, donc on coupe les millièmes
|
| 235 |
// die(var_dump((int)($obs['dateUpdated']/1000), strtotime($res[0]['date_maj'])));
|
236 |
// die(var_dump((int)($obs['dateUpdated']/1000), strtotime($res[0]['date_maj'])));
|
| 236 |
if ((int)($obs['dateUpdated']/1000) > strtotime($res[0]['date_maj'])) {
|
237 |
if ((int)($obs['dateUpdated']/1000) > strtotime($res[0]['date_maj'])) {
|
| 237 |
echo "Obs déjà en base, mise à jour (TB {$res[0]['id_observation']})\n";
|
238 |
echo "Obs déjà en base, mise à jour : ID PN {$obs['id']} ; ID TB {$res[0]['id_observation']} ; utilisateur_tb $email\n";
|
| 238 |
$this->updateFromPN($obs, $res[0]['id_observation']);
|
239 |
$this->updateFromPN($obs, $res[0]['id_observation']);
|
| 239 |
} else {
|
240 |
} else {
|
| 240 |
echo "Obs déjà en base : ID PN {$obs['id']}, ID TB {$res[0]['id_observation']}\n";
|
241 |
echo "Obs déjà en base, déjà à jour : ID PN {$obs['id']} ; ID TB {$res[0]['id_observation']} ; utilisateur_tb $email\n";
|
| 241 |
}
|
242 |
}
|
| 242 |
continue;
|
243 |
continue;
|
| 243 |
}
|
244 |
}
|
| Line 244... |
Line 245... |
| 244 |
|
245 |
|
| Line 257... |
Line 258... |
| 257 |
$tempfile = tempnam("/tmp", "PullPN_") . ".jpg";
|
258 |
$tempfile = tempnam("/tmp", "PullPN_") . ".jpg";
|
| 258 |
$handle = fopen($tempfile, "w");
|
259 |
$handle = fopen($tempfile, "w");
|
| 259 |
fwrite($handle, file_get_contents($image['o']));
|
260 |
fwrite($handle, file_get_contents($image['o']));
|
| 260 |
fclose($handle);
|
261 |
fclose($handle);
|
| Line 261... |
Line 262... |
| 261 |
|
262 |
|
| Line 262... |
Line 263... |
| 262 |
echo "cool on a fait un fichier de " . filesize($tempfile) . " octets là : $tempfile\n";
|
263 |
echo "Image de " . number_format(filesize($tempfile), 0, ',', ' ') . " octets créé : $tempfile\n";
|
| 263 |
|
264 |
|
| 264 |
$params = [
|
265 |
$params = [
|
| 265 |
'name' => 'image' . $i,
|
266 |
'name' => 'image' . $i,
|
| Line 295... |
Line 296... |
| 295 |
}
|
296 |
}
|
| 296 |
}
|
297 |
}
|
| 297 |
// var_dump($images, $tags_images);
|
298 |
// var_dump($images, $tags_images);
|
| 298 |
// die();
|
299 |
// die();
|
| Line -... |
Line 300... |
| - |
|
300 |
|
| - |
|
301 |
$geo = $this->getGeoInfo($obs['geo']);
|
| 299 |
|
302 |
|
| 300 |
// on insère l'obs via le service CelWidgetSaisie
|
303 |
// on insère l'obs via le service CelWidgetSaisie
|
| 301 |
$infos_obs = [
|
- |
|
| 302 |
// 'obsId1[commune_code_insee]' => '',
|
- |
|
| 303 |
'obsId1[commune_nom]' => $obs['geo']['place'] ?? '',
|
304 |
$infos_obs = [
|
| 304 |
'obsId1[date]' => date('d/m/Y', intdiv($obs['dateObs'], 1000)),
|
305 |
'obsId1[date]' => date('d/m/Y', intdiv($obs['dateObs'], 1000)),
|
| 305 |
// 'obsId1[famille]' => '',
|
306 |
'obsId1[latitude]' => $geo['lat'] ?? null,
|
| - |
|
307 |
'obsId1[longitude]' => $geo['lon'] ?? null,
|
| - |
|
308 |
'obsId1[pays]' => $geo['countryCode'] ?? null,
|
| - |
|
309 |
'obsId1[code_postal]' => $geo['postcode'] ?? null,
|
| - |
|
310 |
'obsId1[commune_nom]' => $geo['city'] ?? null,
|
| 306 |
'obsId1[latitude]' => (string)$obs['geo']['lat'] ?? '',
|
311 |
// 'obsId1[commune_code_insee]' => '',
|
| 307 |
// 'obsId1[lieudit]' => '',
|
- |
|
| 308 |
'obsId1[longitude]' => (string)$obs['geo']['lon'] ?? '',
|
312 |
// 'obsId1[lieudit]' => '',
|
| 309 |
// 'obsId1[milieu]' => '',
|
- |
|
| 310 |
// 'obsId1[nom_ret]' => '',
|
313 |
// 'obsId1[milieu]' => '',
|
| - |
|
314 |
'obsId1[nom_sel]' => $obs['currentName'],
|
| - |
|
315 |
// 'obsId1[nom_ret]' => '',
|
| 311 |
'obsId1[nom_sel]' => $obs['currentName'],
|
316 |
// 'obsId1[famille]' => '',
|
| 312 |
'obsId1[certitude]' => 'douteux',
|
317 |
'obsId1[certitude]' => 'douteux',
|
| 313 |
// 'obsId1[notes]' => '',
|
318 |
// 'obsId1[notes]' => '',
|
| 314 |
// 'obsId1[num_nom_ret]' => '',
|
319 |
// 'obsId1[num_nom_ret]' => '',
|
| 315 |
// 'obsId1[num_nom_sel]' => '',
|
320 |
// 'obsId1[num_nom_sel]' => '',
|
| Line 328... |
Line 333... |
| 328 |
];
|
333 |
];
|
| Line 329... |
Line 334... |
| 329 |
|
334 |
|
| 330 |
foreach ($images as $i => $image) {
|
335 |
foreach ($images as $i => $image) {
|
| 331 |
$infos_obs["obsId1[image_nom][$i]"] = $image;
|
336 |
$infos_obs["obsId1[image_nom][$i]"] = $image;
|
| 332 |
}
|
337 |
}
|
| Line 333... |
Line 338... |
| 333 |
// die(var_dump($infos_obs));
|
338 |
// var_dump($infos_obs);
|
| 334 |
|
339 |
|
| 335 |
// curl post $infos_obs
|
340 |
// curl post $infos_obs
|
| 336 |
$ch = curl_init($url_cel_widget_saisie);
|
341 |
$ch = curl_init($url_cel_widget_saisie);
|
| Line 344... |
Line 349... |
| 344 |
if (!$reponse || 200 != $code) {
|
349 |
if (!$reponse || 200 != $code) {
|
| 345 |
throw new Exception("Ça a pété à l'envoi de l'obs :\n $reponse\n avec l'obs : " . json_encode($infos_obs) . "\n");
|
350 |
throw new Exception("Ça a pété à l'envoi de l'obs :\n $reponse\n avec l'obs : " . json_encode($infos_obs) . "\n");
|
| 346 |
}
|
351 |
}
|
| Line 347... |
Line 352... |
| 347 |
|
352 |
|
| 348 |
// var_dump($reponse);
|
353 |
// var_dump($reponse);
|
| 349 |
$id_obs_tb = $this->bdd->proteger(json_decode($reponse, true)['id']);
|
354 |
$id_obs_tb = json_decode($reponse, true)['id'];
|
| 350 |
$id_obs_pn = $this->bdd->proteger($obs['id']);
|
355 |
$id_obs_pn = $obs['id'];
|
| 351 |
// on insère les ids de correspondance obsPN obsTB dans la table cel_plantnet
|
356 |
// on insère les ids de correspondance obsPN obsTB dans la table cel_plantnet
|
| 352 |
$sql = 'INSERT INTO cel_plantnet (id_observation, id_plantnet, date_maj)'
|
357 |
$sql = 'INSERT INTO cel_plantnet (id_observation, id_plantnet, date_maj)'
|
| 353 |
.' VALUES (%s, %s, NOW())'
|
358 |
.' VALUES (%s, %s, NOW())'
|
| 354 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
359 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
| 355 |
$sql = sprintf($sql, $id_obs_tb, $id_obs_pn);
|
360 |
$sql = sprintf($sql, $this->bdd->proteger($id_obs_tb), $this->bdd->proteger($id_obs_pn));
|
| - |
|
361 |
$this->bdd->requeter($sql);
|
| - |
|
362 |
|
| 356 |
$this->bdd->requeter($sql);
|
363 |
echo "Obs insérée en base : ID PN $id_obs_pn ; ID TB $id_obs_tb ; utilisateur_tb $email\n";
|
| 357 |
}
|
364 |
}
|
| 358 |
}
|
365 |
}
|
| Line 359... |
Line 366... |
| 359 |
}
|
366 |
}
|
| Line 449... |
Line 456... |
| 449 |
}
|
456 |
}
|
| Line 450... |
Line 457... |
| 450 |
|
457 |
|
| 451 |
return $infosUtilisateur;
|
458 |
return $infosUtilisateur;
|
| Line -... |
Line 459... |
| - |
|
459 |
}
|
| - |
|
460 |
|
| - |
|
461 |
private function getGeoInfo($obs) {
|
| - |
|
462 |
$geo = [];
|
| - |
|
463 |
if (!isset($obs['lat']) && !isset($obs['lon'])) {
|
| - |
|
464 |
return $geo;
|
| - |
|
465 |
}
|
| - |
|
466 |
|
| - |
|
467 |
// $data = [
|
| - |
|
468 |
// 'hitsPerPage' => 1,
|
| - |
|
469 |
// 'aroundLatLng' => "{$obs['lat']},{$obs['lon']}"
|
| - |
|
470 |
// ];
|
| - |
|
471 |
$headers = [
|
| - |
|
472 |
'X-Algolia-Application-Id' => Config::get('algoliaApplicationId'),
|
| - |
|
473 |
'X-Algolia-API-Key' => Config::get('algoliaAPIKey'),
|
| - |
|
474 |
];
|
| - |
|
475 |
|
| - |
|
476 |
$lat = number_format($obs['lat'], 6, '.', '');
|
| - |
|
477 |
$lon = number_format($obs['lon'], 6, '.', '');
|
| - |
|
478 |
|
| - |
|
479 |
$ch = curl_init(Config::get('urlReverseGeocodingLatLng')."$lat,$lon");
|
| - |
|
480 |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
| - |
|
481 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
| - |
|
482 |
$reponse = curl_exec($ch);
|
| - |
|
483 |
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
| - |
|
484 |
curl_close($ch);
|
| - |
|
485 |
|
| - |
|
486 |
if ($reponse) {
|
| - |
|
487 |
$reponse = json_decode($reponse, true);
|
| - |
|
488 |
// die(var_dump($reponse));
|
| - |
|
489 |
$infos = $reponse['hits'][0];
|
| - |
|
490 |
|
| - |
|
491 |
$geo = [
|
| - |
|
492 |
'lat' => (string) $obs['lat'],
|
| - |
|
493 |
'lon' => (string) $obs['lon'],
|
| - |
|
494 |
'country' => $infos['country']['fr'] ?? $infos['country']['default'],
|
| - |
|
495 |
'city' => $infos['city']['default'][0] ?? null,
|
| - |
|
496 |
'postcode' => $infos['postcode'][0] ?? null,
|
| - |
|
497 |
'countryCode' => strtoupper($infos['country_code']),
|
| - |
|
498 |
];
|
| - |
|
499 |
}
|
| - |
|
500 |
|
| - |
|
501 |
return $geo;
|
| 452 |
}
|
502 |
}
|
| 453 |
|
503 |
|
| 454 |
private function updateFromPN(array $pnObs, string $tbObsId) {
|
504 |
private function updateFromPN(array $pnObs, string $tbObsId) {
|
| 455 |
if (!is_array($pnObs) || !is_string($tbObsId)) {
|
505 |
if (!is_array($pnObs) || !is_string($tbObsId)) {
|
| 456 |
// die(var_dump($pnObs, $tbObsId));
|
506 |
// die(var_dump($pnObs, $tbObsId));
|
| 457 |
throw new Exception("\nBad params types\n");
|
507 |
throw new Exception("\nBad params types, give me an array and an integer plz\n");
|
| Line -... |
Line 508... |
| - |
|
508 |
}
|
| - |
|
509 |
// die(var_dump($pnObs));
|
| - |
|
510 |
|
| - |
|
511 |
// log update date to cel_plantnet
|
| - |
|
512 |
$sql = "UPDATE cel_plantnet SET date_maj = NOW() WHERE id_observation = $tbObsId"
|
| 458 |
}
|
513 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
| 459 |
// die(var_dump($pnObs));
|
514 |
$this->bdd->requeter($sql);
|
| 460 |
|
515 |
|
| 461 |
// check for deleted
|
516 |
// check for deleted
|
| 462 |
if (isset($pnObs['deleted']) && (true === $pnObs['deleted'])) {
|
517 |
if (isset($pnObs['deleted']) && (true === $pnObs['deleted'])) {
|
| 463 |
// est-ce une obs issue de PN ?
|
518 |
// est-ce une obs issue de PN ?
|
| 464 |
//// faut regarder le champ input_source == PlantNet
|
519 |
//// faut regarder le champ input_source == PlantNet
|
| 465 |
$sql = "SELECT input_source FROM occurrence WHERE id = '$tbObsId'"
|
- |
|
| - |
|
520 |
$sql = "SELECT input_source FROM occurrence WHERE id = '$tbObsId'"
|
| 466 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
521 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
| 467 |
$res = $this->bdd->recupererTous($sql);
|
522 |
$res = $this->bdd->recupererTous($sql);
|
| 468 |
die(var_dump($res));
|
523 |
|
| - |
|
524 |
if (isset($res[0]) && ('PlantNet' === $res[0]['input_source'])) {
|
| 469 |
if (isset($res[0]) && ('PlantNet' === $res[0]['input_source'])) {
|
525 |
// oui ? alors supprimer obs !
|
| 470 |
// oui ? alors supprimer obs !
|
526 |
echo "Obs supprimée coté PN, suppression : ID PN {$obs['id']} ; ID TB {$res[0]['id_observation']}\n";
|
| 471 |
echo("obs à supprimer\n");
|
527 |
|
| - |
|
528 |
$sql = "UPDATE photos SET occurrence_id = NULL WHERE occurrence_id = '$tbObsId'"
|
| 472 |
$sql = "DELETE FROM occurrence WHERE id = '$tbObsId'"
|
529 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
| 473 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
530 |
$this->bdd->requeter($sql);
|
| 474 |
$this->bdd->requeter($sql);
|
531 |
|
| 475 |
$sql = "UPDATE photos SET occurrence_id = NULL WHERE occurrence_id = '$tbObsId'"
|
532 |
$sql = "DELETE FROM occurrence WHERE id = '$tbObsId'"
|
| 476 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
533 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
| Line 507... |
Line 564... |
| 507 |
|
564 |
|
| 508 |
// // @TODO : compare votes
|
565 |
// // @TODO : compare votes
|
| 509 |
// // insert_new_votes($pn_sorted_votes, $existing_votes);
|
566 |
// // insert_new_votes($pn_sorted_votes, $existing_votes);
|
| Line 510... |
Line 567... |
| 510 |
}
|
567 |
}
|
| 511 |
|
568 |
|
| - |
|
569 |
private function updateOnePN($pnObsId, $pnProjectId) {
|
| 512 |
private function updateOnePN($id) {
|
570 |
if (!is_int($pnObsId) || !is_string($pnProjectId)) {
|
| - |
|
571 |
die(var_dump($pnObsId, $pnProjectId));
|
| - |
|
572 |
throw new Exception("\nBad params types, give me an integer and a string plz\n");
|
| - |
|
573 |
}
|
| - |
|
574 |
// get PN project list
|
| - |
|
575 |
$list = [];
|
| 513 |
// vérification que l'obs est bien dans la BdD de Tela
|
576 |
$pnProjects = $this->getProjects(); // refresh projects list
|
| - |
|
577 |
foreach ($pnProjects as $project) {
|
| - |
|
578 |
$list[$project['id']] = $project['name'];
|
| - |
|
579 |
}
|
| 514 |
$sql = "SELECT date_maj, id_observation FROM cel_plantnet WHERE id_plantnet = '$id'"
|
580 |
|
| 515 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
581 |
// if project not in list display list
|
| - |
|
582 |
if (!array_key_exists($pnProjectId, $list)) {
|
| - |
|
583 |
echo "Available projects:\n";
|
| 516 |
$res = $this->bdd->recupererTous($sql);
|
584 |
foreach ($list as $projectId => $projectName) {
|
| 517 |
// die(var_dump($res));
|
585 |
echo " - $projectId ($projectName)\n";
|
| - |
|
586 |
}
|
| - |
|
587 |
throw new Exception("Project $pnProjectId does not exist\n");
|
| - |
|
588 |
} else {
|
| - |
|
589 |
$this->currentProject = [
|
| - |
|
590 |
'id' => $pnProjectId,
|
| 518 |
if (!$res) {
|
591 |
'name' => $list[$pnProjectId],
|
| Line 519... |
Line 592... |
| 519 |
throw new Exception("\nPlantnet occurrence id ($id) doesn't exist in tela db. \n");
|
592 |
];
|
| 520 |
}
|
593 |
}
|
| 521 |
|
594 |
|
| 522 |
// l'obs existe déjà à Tela, on vérifie si il faut màj
|
595 |
// get PN obs
|
| 523 |
$urlInfosObs = str_replace(
|
596 |
$urlInfosObs = str_replace(
|
| 524 |
['{token}', '{ids}'],
|
597 |
['{token}', '{project}', '{id}'],
|
| 525 |
[Config::get('tokenPlantnet'), $id],
|
598 |
[Config::get('tokenPlantnet'), $pnProjectId, $pnObsId],
|
| 526 |
Config::get('urlPlantnetBase').Config::get('urlPlantnetObsById')
|
599 |
Config::get('urlPlantnetBase').Config::get('urlPlantnetObsById')
|
| 527 |
);
|
600 |
);
|
| 528 |
$ch = curl_init($urlInfosObs);
|
601 |
$ch = curl_init($urlInfosObs);
|
| 529 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
602 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
| Line 530... |
Line 603... |
| 530 |
$reponse = curl_exec($ch);
|
603 |
$response = curl_exec($ch);
|
| 531 |
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
604 |
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
| 532 |
curl_close($ch);
|
605 |
curl_close($ch);
|
| Line 533... |
Line 606... |
| 533 |
|
606 |
|
| 534 |
if (!$reponse || 200 != $code) {
|
607 |
if (!$response || 200 != $code) {
|
| - |
|
608 |
throw new Exception("\nPlantnet api ($urlInfosObs) replied with code $code : $response\n");
|
| - |
|
609 |
}
|
| - |
|
610 |
|
| - |
|
611 |
// change last modification date to force update
|
| - |
|
612 |
$obs = json_decode($response, true);
|
| - |
|
613 |
$date = new DateTime();
|
| - |
|
614 |
$date->setTimestamp(intdiv($obs['dateUpdated'], 1000) - 1);
|
| - |
|
615 |
$date = $this->bdd->proteger($date->format('Y-m-d H:i:s'));
|
| 535 |
throw new Exception("\nPlantnet api ($urlInfosObs) replied with code $code : $reponse\n");
|
616 |
$sql = "UPDATE cel_plantnet SET date_maj = $date WHERE id_plantnet = '$pnObsId'"
|
| Line 536... |
Line 617... |
| 536 |
}
|
617 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
| 537 |
|
618 |
$this->bdd->requeter($sql);
|
| 538 |
echo "La suite n'a pas été implémentée.\n";
|
619 |
|
| Line 587... |
Line 668... |
| 587 |
. ' VALUES %s'
|
668 |
. ' VALUES %s'
|
| 588 |
. ' ON DUPLICATE KEY UPDATE id_observation=VALUES(id_observation), id_plantnet=VALUES(id_plantnet)'
|
669 |
. ' ON DUPLICATE KEY UPDATE id_observation=VALUES(id_observation), id_plantnet=VALUES(id_plantnet)'
|
| 589 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
670 |
. ' -- ' . __FILE__ . ':' . __LINE__;
|
| 590 |
$values = '';
|
671 |
$values = '';
|
| Line -... |
Line 672... |
| - |
|
672 |
|
| 591 |
|
673 |
echo "Updating matching partners ids table\n";
|
| 592 |
foreach ($data as $id => $corres) {
|
674 |
foreach ($data as $id => $corres) {
|
| 593 |
$id_obs_tb = $this->bdd->proteger($corres['tb']);
|
675 |
$id_obs_tb = $this->bdd->proteger($corres['tb']);
|
| 594 |
$id_obs_pn = $this->bdd->proteger($corres['pn']);
|
676 |
$id_obs_pn = $this->bdd->proteger($corres['pn']);
|
| 595 |
// on insère les ids de correspondance obsPN obsTB dans la table cel_plantnet
|
677 |
// on insère les ids de correspondance obsPN obsTB dans la table cel_plantnet
|
| Line 607... |
Line 689... |
| 607 |
$values = substr($values, 0, -1); // retire la dernière virgule
|
689 |
$values = substr($values, 0, -1); // retire la dernière virgule
|
| 608 |
$sql = sprintf($sqlInsert, $values);
|
690 |
$sql = sprintf($sqlInsert, $values);
|
| 609 |
// var_dump($sql);
|
691 |
// var_dump($sql);
|
| 610 |
$this->bdd->requeter($sql);
|
692 |
$this->bdd->requeter($sql);
|
| Line -... |
Line 693... |
| - |
|
693 |
|
| - |
|
694 |
$count = count($data);
|
| 611 |
|
695 |
echo "Success: #$count updated\n";
|
| Line 612... |
Line 696... |
| 612 |
}
|
696 |
}
|
| 613 |
|
697 |
|
| 614 |
private function updateMatchingPartnersIds() {
|
698 |
private function updateMatchingPartnersIds() {
|