| Line 3... |
Line 3... |
| 3 |
// +-------------------------------------------------------------------------------------------------------------------+
|
3 |
// +-------------------------------------------------------------------------------------------------------------------+
|
| 4 |
/**
|
4 |
/**
|
| 5 |
* Traitement des observations sauvages pour les migrer vers des champs étendus
|
5 |
* Traitement des observations sauvages pour les migrer vers des champs étendus
|
| 6 |
*
|
6 |
*
|
| 7 |
* Description : classe permettant d'affecter des champs étendus aux observations sauvages
|
7 |
* Description : classe permettant d'affecter des champs étendus aux observations sauvages
|
| - |
|
8 |
* Utilisation :
|
| 8 |
* Utilisation : php script.php migration_sauvages -a migrerObservationsSauvages -v 3
|
9 |
* - Pour migrer les données : /opt/lamp/bin/php script.php migration_sauvages -a migrer -v 3
|
| - |
|
10 |
* - Pour exporter les données : /opt/lamp/bin/php script.php migration_sauvages -a exporter -s chemin_vers_fichier_sortie
|
| 9 |
*
|
11 |
*
|
| 10 |
* @category PHP 5.3
|
12 |
* @category PHP 5.3
|
| 11 |
* @package scripts
|
13 |
* @package scripts
|
| 12 |
//Auteur original :
|
14 |
//Auteur original :
|
| 13 |
* @author Aurélien PERONNET <aurelien@tela-botanica.org>
|
15 |
* @author Aurélien PERONNET <aurelien@tela-botanica.org>
|
| Line 16... |
Line 18... |
| 16 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
|
18 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
|
| 17 |
* @version $Id$
|
19 |
* @version $Id$
|
| 18 |
*/
|
20 |
*/
|
| 19 |
// +-------------------------------------------------------------------------------------------------------------------+
|
21 |
// +-------------------------------------------------------------------------------------------------------------------+
|
| 20 |
class MigrationSauvages extends Script {
|
22 |
class MigrationSauvages extends Script {
|
| - |
|
23 |
protected $parametres_autorises = array(
|
| - |
|
24 |
'-s' => array(false, true, "Chemin vers le fichier de sortie pour l'export"));
|
| Line 21... |
Line 25... |
| 21 |
|
25 |
|
| 22 |
// +-------------------------------------------------------------------------------------------------------------------+
|
26 |
// +-------------------------------------------------------------------------------------------------------------------+
|
| 23 |
public function executer() {
|
27 |
public function executer() {
|
| 24 |
include_once dirname(__FILE__).'/bibliotheque/Dao.php';
|
28 |
include_once dirname(__FILE__).'/bibliotheque/Dao.php';
|
| Line 27... |
Line 31... |
| 27 |
// Lancement de l'action demandée
|
31 |
// Lancement de l'action demandée
|
| 28 |
$this->mode_verbeux = $this->getParametre('v');
|
32 |
$this->mode_verbeux = $this->getParametre('v');
|
| 29 |
$cmd = $this->getParametre('a');
|
33 |
$cmd = $this->getParametre('a');
|
| 30 |
try {
|
34 |
try {
|
| 31 |
switch ($cmd) {
|
35 |
switch ($cmd) {
|
| 32 |
case 'migrerObservationsSauvages' :
|
36 |
case 'migrer' :
|
| 33 |
$this->migrerObservationsSauvages();
|
37 |
$this->migrerObservationsSauvages();
|
| 34 |
break;
|
38 |
break;
|
| 35 |
case 'exporterObservationsSauvagesAMigrer' :
|
39 |
case 'exporter' :
|
| 36 |
$this->exporterObservationsSauvagesAMigrer();
|
40 |
$this->exporterObservationsSauvagesAMigrer();
|
| 37 |
break;
|
41 |
break;
|
| 38 |
default :
|
42 |
default :
|
| 39 |
$msg = "Erreur : la commande '$cmd' n'existe pas!\n".
|
43 |
$msg = "Erreur : la commande '$cmd' n'existe pas!\n".
|
| 40 |
"Commandes existantes : migrerObservationsSauvages";
|
44 |
"Commandes existantes : migrer, exporter";
|
| 41 |
throw new Exception($msg);
|
45 |
throw new Exception($msg);
|
| 42 |
}
|
46 |
}
|
| 43 |
} catch (Exception $e) {
|
47 |
} catch (Exception $e) {
|
| 44 |
$this->traiterErreur($e->getMessage());
|
48 |
$this->traiterErreur($e->getMessage());
|
| 45 |
}
|
49 |
}
|
| Line 47... |
Line 51... |
| 47 |
|
51 |
|
| 48 |
private function exporterObservationsSauvagesAMigrer() {
|
52 |
private function exporterObservationsSauvagesAMigrer() {
|
| 49 |
$total = $this->dao->obtenirNbObservationsSauvages();
|
53 |
$total = $this->dao->obtenirNbObservationsSauvages();
|
| 50 |
$pas_liste_obs = 5000;
|
54 |
$pas_liste_obs = 5000;
|
| - |
|
55 |
echo " Traitement des $total observations par paquet de $pas_liste_obs \n";
|
| - |
|
56 |
|
| - |
|
57 |
$fichier = $this->getParametre('s');
|
| 51 |
echo " Traitement des $total observations par paquet de $pas_liste_obs \n";
|
58 |
|
| 52 |
$fp = fopen('/home/jpm/obs.csv', 'w');
|
59 |
$fp = fopen($fichier, 'w');
|
| 53 |
$ecrireEntete = true;
|
60 |
$ecrireEntete = true;
|
| 54 |
for ($i = 0; $i <= $total; $i += $pas_liste_obs) {
|
61 |
for ($i = 0; $i <= $total; $i += $pas_liste_obs) {
|
| 55 |
$liste_observations = $this->dao->obtenirObservationsSauvages($i, $pas_liste_obs);
|
62 |
$liste_observations = $this->dao->obtenirObservationsSauvages($i, $pas_liste_obs);
|
| 56 |
foreach ($liste_observations as $observation) {
|
63 |
foreach ($liste_observations as $observation) {
|
| Line 204... |
Line 211... |
| 204 |
$champs_etendus[] = array('id_observation' => $id,
|
211 |
$champs_etendus[] = array('id_observation' => $id,
|
| 205 |
'cle' => 'adresse',
|
212 |
'cle' => 'adresse',
|
| 206 |
'label' => 'Adresse',
|
213 |
'label' => 'Adresse',
|
| 207 |
'valeur' => $lieu_dit);
|
214 |
'valeur' => $lieu_dit);
|
| 208 |
}
|
215 |
}
|
| 209 |
if ($cote_rue != '') {
|
216 |
if (preg_match('/^(?:2cotes|pair|impair)$/', $cote_rue)) {
|
| 210 |
$champs_etendus[] = array('id_observation' => $id,
|
217 |
$champs_etendus[] = array('id_observation' => $id,
|
| 211 |
'cle' => 'coteRue',
|
218 |
'cle' => 'coteRue',
|
| 212 |
'label' => 'Côté rue',
|
219 |
'label' => 'Côté rue',
|
| 213 |
'valeur' => $cote_rue);
|
220 |
'valeur' => $cote_rue);
|
| 214 |
}
|
221 |
}
|