22,7 → 22,6 |
protected $processedObsId = []; |
|
// Paramètre de suivi et de pagination de l'API des obs PN |
protected $startDate = ''; |
protected $currentPage = ''; |
protected $currentProject = ''; |
protected $hasMore = false; |
38,6 → 37,16 |
'habit' => 'port', |
]; |
|
// Différents types de lifecle possible pour filtrer les obs |
// Modified renvoi les obs en fonction de leur date de modif |
// Created, en fonction de la date de création |
// Deleted, well, you already got it |
protected $lifecycles = [ |
'created', |
'modified', |
'deleted', // deleted peut être très lent |
]; |
|
/** |
* Paramêtres par défaut disponibles pour la ligne de commande |
* le tableau se construit de la forme suivante : |
52,7 → 61,8 |
* @var array |
*/ |
protected $parametres_autorises = array( |
'-startDate' => array(false, '1', 'Date de début (parsée par strtotime). Ex: "YYYY:MM:DD HH:II:SS"'), |
'-startDate' => array(false, true, 'Date de début (parsée par strtotime). Ex: "YYYY:MM:DD HH:II:SS"'), |
'-lifecycle' => array(false, true, 'Par défaut : modified ; Au choix parmi : created/modified/deleted (deleted est lent)'), |
'-pnObsId' => array(false, true, "ID de l'obs chez PlantNet"), |
'-project' => array(false, true, "projectId de l'obs chez PlantNet"), |
'-tbObsId' => array(false, true, "ID de l'obs chez Tela"), |
84,7 → 94,7 |
default: |
$msg = "Erreur : la commande '$cmd' n'existe pas!\n" |
. ', utilisez plutôt :' . "\n" |
. 'php cli.php PullPlantnet -a updateLatest -startDate "YYYY:MM:DD HH:II:SS"' . "\n" |
. 'php cli.php PullPlantnet -a updateLatest -startDate "YYYY:MM:DD HH:II:SS" [[-lifecycle [modified]/created/deleted]]' . "\n" |
. 'php cli.php PullPlantnet -a updateOnePN -pnObsId "xxxxxx" -project "xxxxxx"' . "\n" |
. 'php cli.php PullPlantnet -a updateOneTB -tbObsId "xxxxxx"' . "\n" |
. 'php cli.php PullPlantnet -a updateCorrespondingIdsTable' . "\n" |
98,19 → 108,19 |
* 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') { |
$this->startDate = strtotime($startDate) * 1000; // we need a microtimestamp |
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); |
$observations_PN = $this->getProjectLatest($project, $startDate, $lifecycle); |
$this->updateObs($observations_PN); |
} while ($this->hasMore); |
} |
} |
|
private function getProjectLatest(array $project): array { |
private function getProjectLatest(array $project, int $startDate, string $lifecycle): array { |
$this->currentProject = $project; |
|
if (!$this->currentPage) { |
118,8 → 128,8 |
|
// hop, on appelle le service de PN |
$url_service = str_replace( |
['{project}', '{token}', '{startDate}'], |
[$project['id'], Config::get('tokenPlantnet'), $this->startDate], |
['{project}', '{token}', '{startDate}', '{lifecycle}'], |
[$project['id'], Config::get('tokenPlantnet'), $startDate, $lifecycle], |
Config::get('urlPlantnetBase').Config::get('urlPlantnetLatestChanges') |
); |
// die(var_dump($url_service)); |
170,7 → 180,7 |
curl_close($ch); |
|
if (!$reponse || 200 != $code) { |
throw new Exception("\nPN répond avec une $code à l'adresse $url_service : $reponse\n"); |
throw new Exception("\nPN répond avec une $code à l'adresse $url : $reponse\n"); |
} |
$pnProjects = json_decode($reponse, true); |
|