| Line 1... |
Line 1... |
| 1 |
<?php
|
1 |
<?php
|
| 2 |
// declare(encoding='UTF-8');
|
2 |
// declare(encoding='UTF-8');
|
| 3 |
/**
|
3 |
/**
|
| 4 |
* Script de migration des Observations de la version 1 de la base de données du CEL à la v2.
|
4 |
* Script de migration des Observations de la version 1 de la base de données du CEL à la v2.
|
| - |
|
5 |
* Utilisation : /opt/lampp/bin/php cli.php MigrationObs
|
| 5 |
*
|
6 |
*
|
| 6 |
* @category php 5.2
|
7 |
* @category php 5.2
|
| 7 |
* @package Cel/Scripts
|
8 |
* @package Cel/Scripts
|
| 8 |
* @author Aurélien PERONNET <aurelien@tela-botanica.org>
|
9 |
* @author Aurelien PERONNET <aurelien@tela-botanica.org>
|
| 9 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
10 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
| 10 |
* @copyright Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
|
11 |
* @copyright Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
|
| 11 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
12 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
| 12 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
13 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
| 13 |
* @version $Id$
|
14 |
* @version $Id$
|
| 14 |
*/
|
15 |
*/
|
| 15 |
class MigrationObs extends Cel {
|
16 |
class MigrationObs {
|
| Line 16... |
Line 17... |
| 16 |
|
17 |
|
| 17 |
const truncate = true; //Doit on vider les tables de destination ?
|
18 |
const truncate = true; //Doit on vider les tables de destination ?
|
| 18 |
const dry_run = false;
|
19 |
const dry_run = false;
|
| 19 |
const PATTERN_LAT = '/^[+-]?(?:[1-9][0-9]|[0-9])(?:[.][0-9]+|)$/';
|
20 |
const PATTERN_LAT = '/^[+-]?(?:[1-9][0-9]|[0-9])(?:[.][0-9]+|)$/';
|
| 20 |
const PATTERN_LNG = '/^[+-]?(?:1[0-8][0-9]|[1-9][0-9]|[0-9])(?:[.][0-9]+|)$/';
|
21 |
const PATTERN_LNG = '/^[+-]?(?:1[0-8][0-9]|[1-9][0-9]|[0-9])(?:[.][0-9]+|)$/';
|
| - |
|
22 |
|
| - |
|
23 |
private $bdd = null;
|
| 21 |
|
24 |
private $script = null;
|
| 22 |
public static $bdd_cel_migration;
|
25 |
public static $bdd_cel_migration;
|
| 23 |
public static $bdd_utilisateurs;
|
26 |
public static $bdd_utilisateurs;
|
| 24 |
private $communesOubliees = array();
|
27 |
private $communesOubliees = array();
|
| 25 |
private $tableau_utilisateurs = array();
|
28 |
private $tableau_utilisateurs = array();
|
| Line 36... |
Line 39... |
| 36 |
'id_observation' => 'id',
|
39 |
'id_observation' => 'id',
|
| 37 |
'ordre' => 'ordre',
|
40 |
'ordre' => 'ordre',
|
| 38 |
'ce_utilisateur' => 'traiterIdentifiantUtilisateur',
|
41 |
'ce_utilisateur' => 'traiterIdentifiantUtilisateur',
|
| 39 |
'prenom_utilisateur' => 'traiterPrenomUtilisateur',
|
42 |
'prenom_utilisateur' => 'traiterPrenomUtilisateur',
|
| 40 |
'nom_utilisateur' => 'traiterNomUtilisateur',
|
43 |
'nom_utilisateur' => 'traiterNomUtilisateur',
|
| 41 |
'courriel_utilisateur' => 'identifiant',
|
44 |
'courriel_utilisateur' => 'traiterCourrielUtilisateur',
|
| 42 |
'nom_sel' => 'nom_sel',
|
45 |
'nom_sel' => 'nom_sel',
|
| 43 |
'nom_sel_nn' => 'num_nom_sel',
|
46 |
'nom_sel_nn' => 'num_nom_sel',
|
| 44 |
'nom_ret' => 'nom_ret',
|
47 |
'nom_ret' => 'nom_ret',
|
| 45 |
'nom_ret_nn' => 'num_nom_ret',
|
48 |
'nom_ret_nn' => 'num_nom_ret',
|
| 46 |
'nt' => 'num_taxon',
|
49 |
'nt' => 'num_taxon',
|
| Line 89... |
Line 92... |
| 89 |
'mots_cles' => '',
|
92 |
'mots_cles' => '',
|
| 90 |
'coord_x' => 'latitude',
|
93 |
'coord_x' => 'latitude',
|
| 91 |
'coord_y' => 'longitude',
|
94 |
'coord_y' => 'longitude',
|
| 92 |
'ref_geo' => 'geodatum'
|
95 |
'ref_geo' => 'geodatum'
|
| 93 |
);
|
96 |
);
|
| - |
|
97 |
|
| - |
|
98 |
public function __construct(Conteneur $conteneur) {
|
| - |
|
99 |
$bddMigration = $conteneur->getParametre('database_cel.database_migration');
|
| - |
|
100 |
if ($bddMigration == null || $bddMigration == '') {
|
| - |
|
101 |
echo 'Attention la variable de configuration database_migration dans la section database_cel, contenant la base de données d\'arrivée, doit être remplie '."\n";
|
| - |
|
102 |
exit;
|
| - |
|
103 |
}
|
| - |
|
104 |
$bddIdentification = $conteneur->getParametre('database_ident.database');
|
| - |
|
105 |
if ($bddIdentification == null || $bddIdentification == '') {
|
| - |
|
106 |
echo 'Attention la variable de configuration database dans la section database_ident, contenant la base de données utilisateurs, doit être remplie '."\n";
|
| - |
|
107 |
exit;
|
| - |
|
108 |
}
|
| - |
|
109 |
|
| - |
|
110 |
self::$bdd_cel_migration = $conteneur->getParametre('database_cel.database_migration');
|
| - |
|
111 |
self::$bdd_utilisateurs = $conteneur->getParametre('database_ident.database');
|
| - |
|
112 |
|
| - |
|
113 |
$this->bdd = $conteneur->getBdd();
|
| - |
|
114 |
$this->script = $conteneur->getScript();
|
| - |
|
115 |
}
|
| Line 94... |
Line 116... |
| 94 |
|
116 |
|
| 95 |
/**
|
117 |
/**
|
| 96 |
* Méthode appelée avec une requête de type GET.
|
118 |
* Méthode appelée pour executer le script.
|
| 97 |
*/
|
119 |
*/
|
| 98 |
public function getElement($params) {
|
- |
|
| 99 |
|
- |
|
| 100 |
if(!isset($this->config['database_cel']['database_migration']) || $this->config['database_cel']['database_migration'] == '') {
|
- |
|
| 101 |
echo 'Attention la variable de configuration database_migration dans la section database_cel, contenant la base de données d\'arrivée, doit être remplie '."\n";
|
- |
|
| 102 |
exit;
|
- |
|
| 103 |
}
|
- |
|
| 104 |
|
- |
|
| 105 |
if(!isset($this->config['database_ident']['database']) || $this->config['database_ident']['database'] == '') {
|
- |
|
| 106 |
echo 'Attention la variable de configuration database dans la section database_ident, contenant la base de données utilisateurs, doit être remplie '."\n";
|
- |
|
| 107 |
exit;
|
- |
|
| 108 |
}
|
- |
|
| 109 |
|
- |
|
| 110 |
self::$bdd_cel_migration = $this->config['database_cel']['database_migration'];
|
- |
|
| 111 |
self::$bdd_utilisateurs = $this->config['database_ident']['database'];
|
- |
|
| 112 |
|
120 |
public function executer($params) {
|
| 113 |
echo "--MIGRATION DES OBSERVATIONS --------------------------------------\n";
|
121 |
echo "--MIGRATION DES OBSERVATIONS --------------------------------------\n";
|
| 114 |
//1. TEMPORAIRE : vider les tables de destinations
|
122 |
//1. TEMPORAIRE : vider les tables de destinations
|
| 115 |
if (self::truncate) {
|
123 |
if (self::truncate) {
|
| 116 |
echo "-------------------------------------------------------------------\n\n";
|
124 |
echo "-------------------------------------------------------------------\n";
|
| 117 |
echo " ETAPE 0. Vider les tables ... \n\n";
|
125 |
echo " ETAPE 0. Vider les tables ... \n";
|
| 118 |
echo "-------------------------------------------------------------------\n\n";
|
126 |
echo "-------------------------------------------------------------------\n";
|
| 119 |
$nouvellesTables = array('cel_obs', 'cel_utilisateurs_infos', 'cel_zones_geo');
|
127 |
$nouvellesTables = array('cel_obs', 'cel_utilisateurs_infos', 'cel_zones_geo');
|
| 120 |
foreach ($nouvellesTables as $nomTable) {
|
128 |
foreach ($nouvellesTables as $nomTable) {
|
| 121 |
echo 'Vider la table '.$nomTable.'...';
|
129 |
echo 'Vider la table '.$nomTable.'...';
|
| 122 |
$requeteTruncate = 'TRUNCATE TABLE '.self::$bdd_cel_migration.'.'.$nomTable;
|
130 |
$requeteTruncate = 'TRUNCATE TABLE '.self::$bdd_cel_migration.'.'.$nomTable;
|
| 123 |
$resultatTruncate = $this->executerRequete($requeteTruncate);
|
131 |
$resultatTruncate = $this->bdd->executer($requeteTruncate);
|
| 124 |
echo "ok \n";
|
132 |
echo "ok \n";
|
| 125 |
}
|
- |
|
| 126 |
|
- |
|
| 127 |
echo "\n---------------------------------------------------------------- OK\n\n";
|
133 |
}
|
| Line 128... |
Line 134... |
| 128 |
}
|
134 |
}
|
| 129 |
|
135 |
|
| 130 |
echo "-------------------------------------------------------------------\n\n";
|
136 |
echo "-------------------------------------------------------------------\n";
|
| 131 |
echo " ETAPE 1. Paramétrage ... \n\n";
|
137 |
echo " ETAPE 1. Paramétrage ... \n";
|
| 132 |
echo "-------------------------------------------------------------------\n\n";
|
138 |
echo "-------------------------------------------------------------------\n";
|
| Line 133... |
Line 139... |
| 133 |
$this->getUtilisateurs();
|
139 |
$this->getUtilisateurs();
|
| 134 |
$this->getMotsCles();
|
140 |
$this->getMotsCles();
|
| 135 |
|
141 |
|
| 136 |
echo "-------------------------------------------------------------------\n\n";
|
142 |
echo "-------------------------------------------------------------------\n";
|
| Line 137... |
Line -... |
| 137 |
echo " ETAPE 2. Migration des utilisateurs ... \n\n";
|
- |
|
| 138 |
echo "-------------------------------------------------------------------\n\n";
|
143 |
echo " ETAPE 2. Migration des utilisateurs ... \n";
|
| 139 |
$this->migrerUtilisateurs();
|
144 |
echo "-------------------------------------------------------------------\n";
|
| 140 |
|
145 |
$this->migrerUtilisateurs();
|
| 141 |
|
146 |
|
| Line 142... |
Line 147... |
| 142 |
echo "-------------------------------------------------------------------\n\n";
|
147 |
echo "-------------------------------------------------------------------\n";
|
| 143 |
echo " ETAPE 3. Migration des zone géographiques ... \n\n";
|
148 |
echo " ETAPE 3. Migration des zone géographiques ... \n";
|
| 144 |
echo "-------------------------------------------------------------------\n\n";
|
149 |
echo "-------------------------------------------------------------------\n";
|
| 145 |
$this->migrerZonesGeo();
|
150 |
$this->migrerZonesGeo();
|
| 146 |
|
151 |
|
| 147 |
echo "-------------------------------------------------------------------\n\n";
|
152 |
echo "-------------------------------------------------------------------\n";
|
| 148 |
echo " ETAPE 4. Migration des observations ... \n\n";
|
- |
|
| 149 |
echo "-------------------------------------------------------------------\n\n";
|
153 |
echo " ETAPE 4. Migration des observations ... \n";
|
| Line 150... |
Line 154... |
| 150 |
$this->migrerObs();
|
154 |
echo "-------------------------------------------------------------------\n";
|
| 151 |
$this->mettreANullPrenomNomVide();
|
155 |
$this->migrerObs();
|
| 152 |
$this->ordonnerObs();
|
156 |
$this->mettreANullPrenomNomVide();
|
| 153 |
echo "\n"."\n"."\n";
|
157 |
$this->ordonnerObs();
|
| 154 |
}
|
158 |
}
|
| 155 |
|
159 |
|
| 156 |
public function executerRequeteSimple($requete) {
|
160 |
private function executerRequeteSimple($requete) {
|
| 157 |
// Fonction de commodité pour afficher les requetes au lieu de les executer
|
161 |
// Fonction de commodité pour afficher les requetes au lieu de les executer
|
| 158 |
if (self::dry_run) {
|
162 |
if (self::dry_run) {
|
| Line 159... |
Line 163... |
| 159 |
echo str_replace('),','),'."\n", $requete);
|
163 |
echo str_replace('),','),'."\n", $requete);
|
| 160 |
return true;
|
- |
|
| 161 |
} else {
|
164 |
return true;
|
| Line 162... |
Line 165... |
| 162 |
return parent::executerRequeteSimple($requete);
|
165 |
} else {
|
| 163 |
}
|
166 |
return $this->bdd->executer($requete);
|
| 164 |
}
|
167 |
}
|
| Line 165... |
Line 168... |
| 165 |
|
168 |
}
|
| 166 |
private function getUtilisateurs() {
|
169 |
|
| 167 |
echo "\n-------------------------------------------------------------------\n";
|
170 |
private function getUtilisateurs() {
|
| Line 168... |
Line 171... |
| 168 |
echo "--SELECTION DES UTILISATEURS---------------------------------------\n\n";
|
171 |
echo "SELECTION DES UTILISATEURS\n";
|
| 169 |
|
- |
|
| 170 |
$requete = 'SELECT DISTINCT u_id AS id, u_mail AS mail, u_name AS nom, u_surname AS prenom, u_passwd AS pass '.
|
172 |
|
| Line 171... |
Line 173... |
| 171 |
'FROM cel_inventory INNER JOIN '.self::$bdd_utilisateurs.'.annuaire_tela ON (u_mail = identifiant) ';
|
173 |
$requete = 'SELECT DISTINCT u_id AS id, u_mail AS mail, u_name AS nom, u_surname AS prenom, u_passwd AS pass '.
|
| 172 |
$tableau_utilisateurs = $this->executerRequete($requete);
|
- |
|
| 173 |
|
174 |
'FROM cel_inventory INNER JOIN '.self::$bdd_utilisateurs.'.annuaire_tela ON (u_mail = identifiant) ';
|
| Line 174... |
Line 175... |
| 174 |
foreach( $tableau_utilisateurs as &$utilisateur) {
|
175 |
$tableau_utilisateurs = $this->bdd->requeter($requete);
|
| 175 |
$this->tableau_utilisateurs[$utilisateur['mail']] = $utilisateur;
|
176 |
|
| 176 |
}
|
177 |
foreach( $tableau_utilisateurs as &$utilisateur) {
|
| 177 |
|
178 |
$this->tableau_utilisateurs[$utilisateur['mail']] = $utilisateur;
|
| Line 178... |
Line 179... |
| 178 |
echo sizeof($this->tableau_utilisateurs)." utilisateurs sélectionnés";
|
179 |
}
|
| 179 |
echo "\n-----------------------------------------------------------------OK\n";
|
180 |
|
| 180 |
}
|
181 |
echo sizeof($this->tableau_utilisateurs)." utilisateurs sélectionnés\n";
|
| Line 181... |
Line 182... |
| 181 |
|
182 |
}
|
| 182 |
private function getMotsCles() {
|
- |
|
| 183 |
echo "\n-------------------------------------------------------------------\n";
|
- |
|
| 184 |
echo "--SELECTION DES MOTS-CLES -----------------------------------------\n\n";
|
- |
|
| 185 |
|
- |
|
| 186 |
$requete = 'SELECT cmc_id_proprietaire as id_utilisateur, cmc_id_mot_cle_utilisateur as id_mot_cle, '.
|
- |
|
| 187 |
'cmc_mot_cle as mot_cle '.
|
- |
|
| 188 |
'FROM cel_mots_cles_obs ';
|
- |
|
| 189 |
$tableau_mots_cles = $this->executerRequete($requete);
|
- |
|
| 190 |
|
- |
|
| 191 |
foreach( $tableau_mots_cles as &$mot_cle) {
|
- |
|
| 192 |
$this->tableau_mots_cles[$mot_cle['id_utilisateur']][$mot_cle['id_mot_cle']] = $mot_cle;
|
- |
|
| 193 |
}
|
- |
|
| 194 |
|
- |
|
| 195 |
echo sizeof($this->tableau_mots_cles)." mots-clés sélectionnés";
|
- |
|
| 196 |
echo "\n-----------------------------------------------------------------OK\n";
|
- |
|
| 197 |
|
- |
|
| 198 |
}
|
- |
|
| 199 |
|
- |
|
| 200 |
/**
|
- |
|
| 201 |
* Utiliser cette méthode dans une boucle pour afficher un message suivi du nombre de tour de boucle effectué.
|
- |
|
| 202 |
* Vous devrez vous même gérer le retour à la ligne à la sortie de la boucle.
|
- |
|
| 203 |
*
|
- |
|
| 204 |
* @param string le message d'information.
|
- |
|
| 205 |
* @param int le nombre de départ à afficher.
|
- |
|
| 206 |
* @return void le message est affiché dans la console.
|
- |
|
| 207 |
*/
|
- |
|
| 208 |
protected function afficherAvancement($message, $depart = 0) {
|
- |
|
| 209 |
if (! isset(self::$avancement[$message])) {
|
- |
|
| 210 |
self::$avancement[$message] = $depart;
|
- |
|
| 211 |
echo "$message : ";
|
- |
|
| 212 |
|
- |
|
| 213 |
$actuel =& self::$avancement[$message];
|
183 |
|
| Line 214... |
Line 184... |
| 214 |
echo $actuel++;
|
184 |
private function getMotsCles() {
|
| 215 |
} else {
|
185 |
echo "SELECTION DES MOTS-CLES \n";
|
| 216 |
$actuel =& self::$avancement[$message];
|
186 |
|
| 217 |
|
187 |
$requete = 'SELECT cmc_id_proprietaire as id_utilisateur, cmc_id_mot_cle_utilisateur as id_mot_cle, '.
|
| Line 218... |
Line 188... |
| 218 |
// Cas du passage de 99 (= 2 caractères) à 100 (= 3 caractères)
|
188 |
'cmc_mot_cle as mot_cle '.
|
| 219 |
$passage = 0;
|
189 |
'FROM cel_mots_cles_obs ';
|
| 220 |
if (strlen((string) ($actuel - 1)) < strlen((string) ($actuel))) {
|
190 |
$tableau_mots_cles = $this->bdd->requeter($requete);
|
| 221 |
$passage = 1;
|
191 |
|
| 222 |
}
|
192 |
foreach( $tableau_mots_cles as &$mot_cle) {
|
| Line 223... |
Line 193... |
| 223 |
|
193 |
$this->tableau_mots_cles[$mot_cle['id_utilisateur']][$mot_cle['id_mot_cle']] = $mot_cle;
|
| Line 224... |
Line 194... |
| 224 |
echo str_repeat(chr(8), (strlen((string) $actuel) - $passage));
|
194 |
}
|
| 225 |
echo $actuel++;
|
195 |
|
| 226 |
}
|
196 |
echo sizeof($this->tableau_mots_cles)." mots-clés sélectionnés\n";
|
| 227 |
}
|
197 |
}
|
| 228 |
|
198 |
|
| 229 |
private function migrerUtilisateurs() {
|
199 |
private function migrerUtilisateurs() {
|
| 230 |
$requete = 'INSERT INTO '.self::$bdd_cel_migration.'.cel_utilisateurs_infos '.
|
- |
|
| 231 |
'(id_utilisateur) '.
|
200 |
$requete = 'INSERT INTO '.self::$bdd_cel_migration.'.cel_utilisateurs_infos '.
|
| Line 232... |
Line 201... |
| 232 |
'VALUES ';
|
201 |
'(id_utilisateur) '.
|
| 233 |
|
- |
|
| 234 |
$sous_requete = array();
|
202 |
'VALUES ';
|
| Line 235... |
Line 203... |
| 235 |
foreach ($this->tableau_utilisateurs as $id => &$utilisateur) {
|
203 |
|
| 236 |
$sous_requete[] = '('.$this->proteger($utilisateur['id']).')';
|
204 |
$sous_requete = array();
|
| 237 |
}
|
205 |
foreach ($this->tableau_utilisateurs as $id => &$utilisateur) {
|
| 238 |
$requete .= implode(',', $sous_requete);
|
206 |
$sous_requete[] = '('.$this->bdd->proteger($utilisateur['id']).')';
|
| Line 239... |
Line 207... |
| 239 |
|
207 |
}
|
| 240 |
$migration_utilisateurs = $this->executerRequeteSimple($requete);
|
208 |
$requete .= implode(',', $sous_requete);
|
| Line 241... |
Line 209... |
| 241 |
|
209 |
|
| Line 242... |
Line 210... |
| 242 |
if ($migration_utilisateurs) {
|
210 |
$migration_utilisateurs = $this->executerRequeteSimple($requete);
|
| Line 243... |
Line 211... |
| 243 |
echo "Migration utilisateurs : ".count($sous_requete);
|
211 |
|
| 244 |
} else {
|
212 |
if ($migration_utilisateurs) {
|
| 245 |
exit('Erreur lors de la migration des utilisateurs '."\n");
|
213 |
echo "Migration utilisateurs : ".count($sous_requete);
|
| Line 277... |
Line 245... |
| 277 |
$lat_long = $this->convertirUtmVersLatLong($zone_geo['x_utm'],$zone_geo['y_utm'],$zone_geo['sector']);
|
245 |
$lat_long = $this->convertirUtmVersLatLong($zone_geo['x_utm'],$zone_geo['y_utm'],$zone_geo['sector']);
|
| Line 278... |
Line 246... |
| 278 |
|
246 |
|
| 279 |
$indice_tableau_localites = $this->construireIndiceTableauLocalites($zone_geo['name'], $zone_geo['insee_code']);
|
247 |
$indice_tableau_localites = $this->construireIndiceTableauLocalites($zone_geo['name'], $zone_geo['insee_code']);
|
| Line 280... |
Line 248... |
| 280 |
$this->tableau_zones_geo[$indice_tableau_localites] = $zone_geo;
|
248 |
$this->tableau_zones_geo[$indice_tableau_localites] = $zone_geo;
|
| 281 |
|
249 |
|
| 282 |
$sous_requete_insertion_valeurs .= '('.$this->proteger($zone_geo['nouveau_code_geo']).','.
|
250 |
$sous_requete_insertion_valeurs .= '('.$this->bdd->proteger($zone_geo['nouveau_code_geo']).','.
|
| 283 |
$this->proteger($zone_geo['insee_code']).','.
|
251 |
$this->bdd->proteger($zone_geo['insee_code']).','.
|
| 284 |
$this->proteger($zone_geo['name']).','.
|
252 |
$this->bdd->proteger($zone_geo['name']).','.
|
| 285 |
$this->proteger($zone_geo['sector']).','.
|
253 |
$this->bdd->proteger($zone_geo['sector']).','.
|
| 286 |
$this->proteger($zone_geo['x_utm']).','.
|
254 |
$this->bdd->proteger($zone_geo['x_utm']).','.
|
| 287 |
$this->proteger($zone_geo['y_utm']).','.
|
255 |
$this->bdd->proteger($zone_geo['y_utm']).','.
|
| 288 |
$this->proteger($lat_long['lat']).','.
|
256 |
$this->bdd->proteger($lat_long['lat']).','.
|
| 289 |
$this->proteger($lat_long['long']).','.
|
257 |
$this->bdd->proteger($lat_long['long']).','.
|
| 290 |
$this->proteger($zone_geo['update_date']).
|
258 |
$this->bdd->proteger($zone_geo['update_date']).
|
| Line 291... |
Line 259... |
| 291 |
'),';
|
259 |
'),';
|
| Line 292... |
Line 260... |
| 292 |
}
|
260 |
}
|
| Line 301... |
Line 269... |
| 301 |
return;
|
269 |
return;
|
| 302 |
}
|
270 |
}
|
| Line 303... |
Line 271... |
| 303 |
|
271 |
|
| 304 |
if ($migration_zones_geo) {
|
272 |
if ($migration_zones_geo) {
|
| 305 |
$nbTotal ++;
|
273 |
$nbTotal ++;
|
| 306 |
$this->afficherAvancement('Migration des zones (par '.$pas.')', $nbTotal);
|
274 |
$this->script->afficherAvancement('Migration des zones (par '.$pas.')', $nbTotal);
|
| 307 |
} else {
|
275 |
} else {
|
| 308 |
exit('Erreur lors de la migration des zones géo '.$i.' à '.($i+$pas)."\n");
|
276 |
exit('Erreur lors de la migration des zones géo '.$i.' à '.($i+$pas)."\n");
|
| 309 |
}
|
277 |
}
|
| 310 |
}
|
278 |
}
|
| 311 |
echo "\n---------------------------------------------------------------- OK\n\n";
|
279 |
echo "\n";
|
| Line 312... |
Line 280... |
| 312 |
}
|
280 |
}
|
| 313 |
|
281 |
|
| Line 328... |
Line 296... |
| 328 |
$pas = 1000;
|
296 |
$pas = 1000;
|
| 329 |
$nbTotal = 0;
|
297 |
$nbTotal = 0;
|
| Line 330... |
Line 298... |
| 330 |
|
298 |
|
| 331 |
//Selectionner le nombre d'observations
|
299 |
//Selectionner le nombre d'observations
|
| 332 |
$requeteNbObs = "SELECT COUNT(*) as nb FROM cel_inventory";
|
300 |
$requeteNbObs = "SELECT COUNT(*) as nb FROM cel_inventory";
|
| 333 |
$resultatNbObs = $this->executerRequete($requeteNbObs);
|
- |
|
| Line 334... |
Line 301... |
| 334 |
$fin = $resultatNbObs[0]['nb'];
|
301 |
$fin = $this->bdd->requeter($requeteNbObs, Bdd::SQL_RETOUR_COLONNE);
|
| 335 |
|
302 |
|
| - |
|
303 |
for ($i = $debut; $i < $fin ; $i += $pas) {
|
| 336 |
for ($i = $debut; $i < $fin ; $i += $pas) {
|
304 |
$requete_selection_obs = 'SELECT * '.
|
| - |
|
305 |
'FROM cel_inventory '.
|
| 337 |
$requete_selection_obs = 'SELECT * FROM cel_inventory '.
|
306 |
'ORDER BY identifiant '.
|
| Line 338... |
Line 307... |
| 338 |
'ORDER BY identifiant LIMIT '.$i.','.$pas;
|
307 |
'LIMIT '.$i.','.$pas;
|
| Line 339... |
Line 308... |
| 339 |
$observations = $this->requeter($requete_selection_obs);
|
308 |
$observations = $this->bdd->requeter($requete_selection_obs);
|
| 340 |
|
309 |
|
| Line 357... |
Line 326... |
| 357 |
|
326 |
|
| Line 358... |
Line 327... |
| 358 |
$requete_insertion_observations = rtrim($requete_insertion_observations, ',');
|
327 |
$requete_insertion_observations = rtrim($requete_insertion_observations, ',');
|
| 359 |
|
328 |
|
| 360 |
$migration_observations = $this->executerRequeteSimple($requete_insertion_observations);
|
329 |
$migration_observations = $this->executerRequeteSimple($requete_insertion_observations);
|
| 361 |
} else {
|
330 |
} else {
|
| 362 |
echo 'Fin de migration des observations '."\n"."\n";
|
331 |
echo "Fin de migration des observations\n";
|
| Line 363... |
Line 332... |
| 363 |
return;
|
332 |
return;
|
| 364 |
}
|
333 |
}
|
| 365 |
|
334 |
|
| 366 |
if ($migration_observations) {
|
335 |
if ($migration_observations) {
|
| 367 |
$nbTotal ++;
|
336 |
$nbTotal ++;
|
| 368 |
$this->afficherAvancement('Migration des observations (par '.$pas.')', $nbTotal);
|
337 |
$this->script->afficherAvancement('Migration des observations (par '.$pas.')', $nbTotal);
|
| 369 |
} else {
|
338 |
} else {
|
| - |
|
339 |
exit('Erreur lors de la migration des observation de '.$i.' à '.($i+$pas)."\n");
|
| 370 |
exit('Erreur lors de la migration des observation de '.$i.' à '.($i+$pas)."\n");
|
340 |
}
|
| 371 |
}
|
341 |
}
|
| 372 |
}
|
342 |
echo "\n";
|
| 373 |
if (sizeof($this->communesOubliees) > 0) {
|
- |
|
| 374 |
echo "\nxxxxxxxxx communes oubliées : ".sizeof($this->communesOubliees)." xxxxxxxxx \\n";
|
343 |
if (sizeof($this->communesOubliees) > 0) {
|
| Line 375... |
Line 344... |
| 375 |
}
|
344 |
echo "xxxxxxxxx Communes ignorées : ".sizeof($this->communesOubliees)." xxxxxxxxx \n";
|
| 376 |
echo "\n---------------------------------------------------------------- OK\n\n";
|
345 |
}
|
| 377 |
}
|
346 |
}
|
| Line 405... |
Line 374... |
| 405 |
return $nouvelle_obs;
|
374 |
return $nouvelle_obs;
|
| 406 |
}
|
375 |
}
|
| Line 407... |
Line 376... |
| 407 |
|
376 |
|
| 408 |
private function protegerSiNonNull($valeur) {
|
377 |
private function protegerSiNonNull($valeur) {
|
| 409 |
if ($valeur != 'NULL') {
|
378 |
if ($valeur != 'NULL') {
|
| 410 |
$valeur = $this->proteger($valeur);
|
379 |
$valeur = $this->bdd->proteger($valeur);
|
| 411 |
}
|
380 |
}
|
| 412 |
return $valeur;
|
381 |
return $valeur;
|
| Line 413... |
Line 382... |
| 413 |
}
|
382 |
}
|
| Line 423... |
Line 392... |
| 423 |
}
|
392 |
}
|
| 424 |
return $retour;
|
393 |
return $retour;
|
| 425 |
}
|
394 |
}
|
| Line 426... |
Line 395... |
| 426 |
|
395 |
|
| 427 |
private function traiterLat(&$observation) {
|
396 |
private function traiterLat(&$observation) {
|
| 428 |
if ($this->etreNull($observation['coord_x'])) {
|
397 |
if ($this->bdd->etreNull($observation['coord_x'])) {
|
| 429 |
$observation['coord_x'] = 'NULL';
|
398 |
$observation['coord_x'] = 'NULL';
|
| 430 |
} else if (preg_match(self::PATTERN_LAT, $observation['coord_x']) == false) {
|
399 |
} else if (preg_match(self::PATTERN_LAT, $observation['coord_x']) == false) {
|
| 431 |
$latNote = 'Latitude éronnée : '.$observation['coord_x'];
|
400 |
$latNote = 'Latitude éronnée : '.$observation['coord_x'];
|
| 432 |
if ($this->etreNull($observation['commentaire'])) {
|
401 |
if ($this->bdd->etreNull($observation['commentaire'])) {
|
| 433 |
$observation['commentaire'] = $latNote;
|
402 |
$observation['commentaire'] = $latNote;
|
| 434 |
} else {
|
403 |
} else {
|
| 435 |
$observation['commentaire'] .= "\n".$latNote;
|
404 |
$observation['commentaire'] .= "\n".$latNote;
|
| 436 |
}
|
405 |
}
|
| Line 439... |
Line 408... |
| 439 |
$retour = $observation['coord_x'];
|
408 |
$retour = $observation['coord_x'];
|
| 440 |
return $retour;
|
409 |
return $retour;
|
| 441 |
}
|
410 |
}
|
| Line 442... |
Line 411... |
| 442 |
|
411 |
|
| 443 |
private function traiterLng(&$observation) {
|
412 |
private function traiterLng(&$observation) {
|
| 444 |
if ($this->etreNull($observation['coord_y'])) {
|
413 |
if ($this->bdd->etreNull($observation['coord_y'])) {
|
| 445 |
$observation['coord_y'] = 'NULL';
|
414 |
$observation['coord_y'] = 'NULL';
|
| 446 |
} else if (preg_match(self::PATTERN_LNG, $observation['coord_y']) == false) {
|
415 |
} else if (preg_match(self::PATTERN_LNG, $observation['coord_y']) == false) {
|
| 447 |
$lngNote = 'Longitude éronnée : '.$observation['coord_y'];
|
416 |
$lngNote = 'Longitude éronnée : '.$observation['coord_y'];
|
| 448 |
if ($this->etreNull($observation['commentaire'])) {
|
417 |
if ($this->bdd->etreNull($observation['commentaire'])) {
|
| 449 |
$observation['commentaire'] = $lngNote;
|
418 |
$observation['commentaire'] = $lngNote;
|
| 450 |
} else {
|
419 |
} else {
|
| 451 |
$observation['commentaire'] .= "\n".$lngNote;
|
420 |
$observation['commentaire'] .= "\n".$lngNote;
|
| 452 |
}
|
421 |
}
|
| Line 532... |
Line 501... |
| 532 |
}
|
501 |
}
|
| Line 533... |
Line 502... |
| 533 |
|
502 |
|
| 534 |
private function traiterNomUtilisateur($ligne_observation) {
|
503 |
private function traiterNomUtilisateur($ligne_observation) {
|
| Line 535... |
Line 504... |
| 535 |
$mail_observation = $ligne_observation['identifiant'];
|
504 |
$mail_observation = $ligne_observation['identifiant'];
|
| 536 |
|
505 |
|
| 537 |
$retour = '';
|
506 |
$retour = 'NULL';
|
| 538 |
if (isset($this->tableau_utilisateurs[$mail_observation])) {
|
507 |
if (isset($this->tableau_utilisateurs[$mail_observation])) {
|
| 539 |
$nom = $this->tableau_utilisateurs[$mail_observation]['nom'];
|
508 |
$nom = $this->tableau_utilisateurs[$mail_observation]['nom'];
|
| 540 |
$retour = self::formaterMotEnMajuscule($nom);
|
509 |
$retour = self::formaterMotEnMajuscule($nom);
|
| 541 |
}
|
510 |
}
|
| - |
|
511 |
return $retour;
|
| - |
|
512 |
}
|
| - |
|
513 |
|
| - |
|
514 |
private function traiterCourrielUtilisateur($observation) {
|
| - |
|
515 |
$courriel = $observation['identifiant'];
|
| - |
|
516 |
|
| - |
|
517 |
$retour = 'NULL';
|
| - |
|
518 |
if ($this->mailValide($courriel)) {
|
| - |
|
519 |
$retour = $courriel;
|
| - |
|
520 |
}
|
| - |
|
521 |
return $retour;
|
| Line 542... |
Line 522... |
| 542 |
return $retour;
|
522 |
}
|
| 543 |
}
|
523 |
|
| 544 |
|
524 |
|
| 545 |
public static function formaterMotPremiereLettreChaqueMotEnMajuscule($chaine, $encodage= 'UTF-8') {
|
525 |
public static function formaterMotPremiereLettreChaqueMotEnMajuscule($chaine, $encodage= 'UTF-8') {
|
| Line 607... |
Line 587... |
| 607 |
|
587 |
|
| 608 |
$nom = str_replace("'",'_',$nom);
|
588 |
$nom = str_replace("'",'_',$nom);
|
| 609 |
$nom = str_replace(' ','_',$nom);
|
589 |
$nom = str_replace(' ','_',$nom);
|
| 610 |
$nom = str_replace('-','_',$nom);
|
590 |
$nom = str_replace('-','_',$nom);
|
| 611 |
$nom = str_replace(' ','_',$nom);
|
591 |
$nom = str_replace(' ','_',$nom);
|
| Line 612... |
Line 592... |
| 612 |
$indice = strtolower($nom).substr($id,0,2);
|
592 |
$indice = strtolower($nom).substr($id, 0, 2);
|
| 613 |
|
593 |
|
| Line 614... |
Line 594... |
| 614 |
return $indice;
|
594 |
return $indice;
|
| Line 624... |
Line 604... |
| 624 |
} else if ($utilisateur != '') {
|
604 |
} else if ($utilisateur != '') {
|
| 625 |
// sinon si c'est un mail inconnu, on garde le md5
|
605 |
// sinon si c'est un mail inconnu, on garde le md5
|
| 626 |
if ($this->mailValide($utilisateur)) {
|
606 |
if ($this->mailValide($utilisateur)) {
|
| 627 |
$retour = md5($utilisateur);
|
607 |
$retour = md5($utilisateur);
|
| 628 |
}
|
608 |
}
|
| - |
|
609 |
} else if ($utilisateur == '') {
|
| - |
|
610 |
$retour = 'NULL';
|
| 629 |
}
|
611 |
}
|
| 630 |
return $retour;
|
612 |
return $retour;
|
| 631 |
}
|
613 |
}
|
| Line 632... |
Line 614... |
| 632 |
|
614 |
|
| 633 |
public function mailValide($mail) {
|
615 |
private function mailValide($mail) {
|
| 634 |
// vérification bidon mais ça suffit pour ici
|
616 |
// vérification bidon mais ça suffit pour ici
|
| 635 |
return !(strpos('@', $mail) === false);
|
617 |
return !(strpos($mail, '@') === false);
|
| Line 636... |
Line 618... |
| 636 |
}
|
618 |
}
|
| 637 |
|
619 |
|
| 638 |
private function mettreANullPrenomNomVide() {
|
620 |
private function mettreANullPrenomNomVide() {
|
| 639 |
$bdd = self::$bdd_cel_migration;
|
621 |
$bdd = self::$bdd_cel_migration;
|
| 640 |
$requete = "UPDATE $bdd.cel_obs ".
|
622 |
$requete = "UPDATE $bdd.cel_obs ".
|
| 641 |
'SET prenom_utilisateur = NULL '.
|
623 |
'SET prenom_utilisateur = NULL '.
|
| Line 642... |
Line 624... |
| 642 |
"WHERE prenom_utilisateur = '' ";
|
624 |
"WHERE prenom_utilisateur = '' ";
|
| 643 |
$this->executer($requete);
|
625 |
$this->bdd->executer($requete);
|
| 644 |
|
626 |
|
| 645 |
$requete = "UPDATE $bdd.cel_obs ".
|
627 |
$requete = "UPDATE $bdd.cel_obs ".
|
| 646 |
'SET nom_utilisateur = NULL '.
|
628 |
'SET nom_utilisateur = NULL '.
|
| 647 |
"WHERE nom_utilisateur = '' ";
|
629 |
"WHERE nom_utilisateur = '' ";
|
| 648 |
$this->executer($requete);
|
630 |
$this->bdd->executer($requete);
|