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 Mots Clés de la version 1 de la base de données du CEL à la v2.
|
4 |
* Script de migration des Mots Clés de la version 1 de la base de données du CEL à la v2.
|
- |
|
5 |
* Utilisation : /opt/lampp/bin/php cli.php MigrationMotsCles
|
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 MigrationMotsCles extends Cel {
|
16 |
class MigrationMotsCles {
|
Line 16... |
Line 17... |
16 |
|
17 |
|
17 |
const SEPARATEUR_MOT_CLE_TEXTE = ',';
|
18 |
const SEPARATEUR_MOT_CLE_TEXTE = ',';
|
18 |
const truncate = true; //Doit on vider les tables de destination ?
|
19 |
const truncate = true; //Doit on vider les tables de destination ?
|
Line -... |
Line 20... |
- |
|
20 |
const dry_run = false;
|
- |
|
21 |
|
19 |
const dry_run = false;
|
22 |
private $bdd = null;
|
20 |
|
23 |
private $script = null;
|
21 |
private $nouvellesTables = array('cel_mots_cles_obs', 'cel_mots_cles_images', 'cel_images_mots_cles', 'cel_obs_mots_cles');
|
24 |
private $nouvellesTables = array('cel_mots_cles_obs', 'cel_mots_cles_images', 'cel_images_mots_cles', 'cel_obs_mots_cles');
|
22 |
public static $bdd_cel_migration;
|
25 |
public static $bdd_cel_migration;
|
Line 27... |
Line 30... |
27 |
* La clé est un md5 du message à afficher au démarrage de la boucle.
|
30 |
* La clé est un md5 du message à afficher au démarrage de la boucle.
|
28 |
* @var array
|
31 |
* @var array
|
29 |
*/
|
32 |
*/
|
30 |
private static $avancement = array();
|
33 |
private static $avancement = array();
|
Line 31... |
Line -... |
31 |
|
- |
|
32 |
/**
|
34 |
|
33 |
* Méthode appelée avec une requête de type GET.
|
- |
|
34 |
*/
|
35 |
public function __construct(Conteneur $conteneur) {
|
35 |
public function getElement($params) {
|
36 |
$bddMigration = $conteneur->getParametre('database_cel.database_migration');
|
36 |
if (!isset($this->config['database_cel']['database_migration']) || $this->config['database_cel']['database_migration'] == '') {
|
37 |
if ($bddMigration == null || $bddMigration == '') {
|
37 |
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";
|
38 |
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";
|
38 |
exit;
|
39 |
exit;
|
39 |
}
|
- |
|
40 |
|
40 |
}
|
- |
|
41 |
$bddIdentification = $conteneur->getParametre('database_ident.database');
|
41 |
if (!isset($this->config['database_ident']['database']) || $this->config['database_ident']['database'] == '') {
|
42 |
if ($bddIdentification == null || $bddIdentification == '') {
|
42 |
echo 'Attention la variable de configuration database dans la section database_ident, contenant la base de données utilisateurs, doit être remplie '."\n";
|
43 |
echo 'Attention la variable de configuration database dans la section database_ident, contenant la base de données utilisateurs, doit être remplie '."\n";
|
43 |
exit;
|
44 |
exit;
|
Line 44... |
Line 45... |
44 |
}
|
45 |
}
|
45 |
|
46 |
|
- |
|
47 |
self::$bdd_cel_migration = $conteneur->getParametre('database_cel.database_migration');
|
- |
|
48 |
self::$bdd_utilisateurs = $conteneur->getParametre('database_ident.database');
|
- |
|
49 |
$this->bdd = $conteneur->getBdd();
|
Line -... |
Line 50... |
- |
|
50 |
$this->script = $conteneur->getScript();
|
- |
|
51 |
}
|
- |
|
52 |
|
- |
|
53 |
/**
|
46 |
self::$bdd_cel_migration = $this->config['database_cel']['database_migration'];
|
54 |
* Méthode appelée pour executer le script.
|
47 |
self::$bdd_utilisateurs = $this->config['database_ident']['database'];
|
55 |
*/
|
48 |
|
56 |
public function executer($params) {
|
49 |
echo "--MIGRATION DES MOTS CLES --------------------------------------\n";
|
57 |
echo "--MIGRATION DES MOTS CLES --------------------------------------\n";
|
50 |
if (self::truncate) {
|
58 |
if (self::truncate) {
|
51 |
echo "-------------------------------------------------------------------\n";
|
59 |
echo "-------------------------------------------------------------------\n";
|
52 |
echo " ETAPE 0. Vider les tables ... \n\n";
|
- |
|
53 |
echo "-------------------------------------------------------------------\n";
|
60 |
echo " ETAPE 0. Vider les tables ... \n";
|
Line 54... |
Line 61... |
54 |
$this->viderTables();
|
61 |
echo "-------------------------------------------------------------------\n";
|
55 |
echo "---------------------------------------------------------------- OK\n";
|
62 |
$this->viderTables();
|
56 |
}
|
63 |
}
|
57 |
|
64 |
|
58 |
echo "-------------------------------------------------------------------\n";
|
- |
|
- |
|
65 |
echo "-------------------------------------------------------------------\n";
|
59 |
echo " ETAPE 1. Paramétrage ... \n";
|
66 |
echo " ETAPE 1. Paramétrage ... \n";
|
60 |
echo "-------------------------------------------------------------------\n";
|
67 |
echo "-------------------------------------------------------------------\n";
|
61 |
$this->getUtilisateurs();
|
68 |
$this->getUtilisateurs();
|
62 |
echo "\n"."\n"."\n";
|
69 |
|
63 |
echo "-------------------------------------------------------------------\n";
|
- |
|
64 |
echo " ETAPE 2. Migration des mots clés ... \n";
|
70 |
echo "-------------------------------------------------------------------\n";
|
65 |
echo "-------------------------------------------------------------------\n";
|
- |
|
- |
|
71 |
echo " ETAPE 2. Migration des mots clés ... \n";
|
66 |
$this->migrerTableMotsClesObs();
|
72 |
echo "-------------------------------------------------------------------\n";
|
67 |
echo "\n---------------------------------------------------------------- OK\n";
|
73 |
$this->migrerTableMotsClesObs();
|
68 |
$this->migrerTableMotsClesImages();
|
74 |
$this->migrerTableMotsClesImages();
|
69 |
echo "\n"."\n"."\n";
|
75 |
|
70 |
echo "-------------------------------------------------------------------\n";
|
76 |
echo "-------------------------------------------------------------------\n";
|
71 |
echo " ETAPE 3. Migration des liaisons mots clés ... \n";
|
- |
|
Line 72... |
Line 77... |
72 |
echo "-------------------------------------------------------------------\n";
|
77 |
echo " ETAPE 3. Migration des liaisons mots clés ... \n";
|
73 |
$this->migrerLiaisonsMotsClesObs();
|
78 |
echo "-------------------------------------------------------------------\n";
|
74 |
$this->migrerLiaisonsMotsClesImages();
|
79 |
$this->migrerLiaisonsMotsClesObs();
|
75 |
echo "\n"."\n"."\n";
|
80 |
$this->migrerLiaisonsMotsClesImages();
|
76 |
|
81 |
|
77 |
echo "-------------------------------------------------------------------\n";
|
82 |
echo "-------------------------------------------------------------------\n";
|
78 |
echo " ETAPE 4. Génération des index des mots clés ... \n";
|
- |
|
79 |
echo "-------------------------------------------------------------------\n";
|
83 |
echo " ETAPE 4. Génération des index des mots clés ... \n";
|
Line 80... |
Line 84... |
80 |
$this->genererIndexTexteMotsClesObs();
|
84 |
echo "-------------------------------------------------------------------\n";
|
81 |
$this->genererIndexTexteMotsClesImages();
|
85 |
$this->genererIndexTexteMotsClesObs();
|
82 |
$this->mettreANullMotsClesTxtVide();
|
86 |
$this->genererIndexTexteMotsClesImages();
|
83 |
echo "\n"."\n"."\n";
|
87 |
$this->mettreANullMotsClesTxtVide();
|
84 |
}
|
88 |
}
|
85 |
|
89 |
|
86 |
private function viderTables() {
|
90 |
private function viderTables() {
|
87 |
foreach ($this->nouvellesTables as $nomTable) {
|
91 |
foreach ($this->nouvellesTables as $nomTable) {
|
Line 88... |
Line 92... |
88 |
echo 'Vider la table '.$nomTable.'...';
|
92 |
echo 'Vider la table '.$nomTable.'...';
|
89 |
$requete = 'TRUNCATE TABLE '.self::$bdd_cel_migration.'.'.$nomTable;
|
93 |
$requete = 'TRUNCATE TABLE '.self::$bdd_cel_migration.'.'.$nomTable;
|
90 |
$resultat = $this->executerRequete($requete);
|
94 |
$resultat = $this->bdd->executer($requete);
|
91 |
echo "ok \n";
|
95 |
echo "ok \n";
|
92 |
}
|
96 |
}
|
93 |
}
|
97 |
}
|
94 |
|
98 |
|
95 |
public function executerRequeteSimple($requete) {
|
99 |
private function executerRequeteSimple($requete) {
|
Line 96... |
Line 100... |
96 |
// Fonction de commodité pour afficher les requetes au lieu de les executer
|
100 |
// Fonction de commodité pour afficher les requetes au lieu de les executer
|
Line 97... |
Line 101... |
97 |
if (self::dry_run) {
|
101 |
if (self::dry_run) {
|
98 |
echo str_replace('),','),'."\n", $requete);
|
- |
|
99 |
return true;
|
102 |
echo str_replace('),','),'."\n", $requete);
|
Line 100... |
Line 103... |
100 |
} else {
|
103 |
return true;
|
101 |
return parent::executerRequeteSimple($requete);
|
104 |
} else {
|
102 |
}
|
105 |
return $this->bdd->executer($requete);
|
Line 103... |
Line 106... |
103 |
|
106 |
}
|
104 |
}
|
107 |
|
105 |
|
108 |
}
|
Line 106... |
Line 109... |
106 |
|
109 |
|
107 |
private function getUtilisateurs() {
|
- |
|
108 |
echo "\n-------------------------------------------------------------------\n";
|
110 |
|
Line 109... |
Line 111... |
109 |
echo "--SELECTION DES UTILISATEURS---------------------------------------\n\n";
|
111 |
private function getUtilisateurs() {
|
110 |
|
112 |
echo "SELECTION DES UTILISATEURS\n";
|
111 |
$requete = 'SELECT U_ID as id, U_MAIL as mail, U_NAME as nom, U_SURNAME as prenom, U_PASSWD as pass '.
|
113 |
|
Line 127... |
Line 129... |
127 |
private function migrerTableMotsClesImages() {
|
129 |
private function migrerTableMotsClesImages() {
|
128 |
$this->migrerTableMotsCles('images');
|
130 |
$this->migrerTableMotsCles('images');
|
129 |
}
|
131 |
}
|
Line 130... |
Line 132... |
130 |
|
132 |
|
131 |
private function migrerTableMotsCles($image_ou_obs) {
|
133 |
private function migrerTableMotsCles($image_ou_obs) {
|
132 |
echo "--MIGRATION DES MOTS CLES $image_ou_obs ---------------------------------\n";
|
134 |
echo "MIGRATION DES MOTS CLES $image_ou_obs\n";
|
Line 133... |
Line 135... |
133 |
$pas = 1;
|
135 |
$pas = 1;
|
134 |
|
136 |
|
135 |
//limite des mots clés
|
137 |
//limite des mots clés
|
136 |
$requeteNbMotsCles = 'SELECT count(*) as nb FROM cel_mots_cles_'.$image_ou_obs;
|
- |
|
- |
|
138 |
$requeteNbMotsCles = 'SELECT count(*) as nb FROM cel_mots_cles_'.$image_ou_obs;
|
137 |
$resultatNbMotsCles = $this->executerRequete($requeteNbMotsCles);
|
139 |
$nbMotsCles = (int) $this->bdd->requeter($requeteNbMotsCles, Bdd::SQL_RETOUR_COLONNE);
|
138 |
$nbMotsCles = (int) $resultatNbMotsCles[0]['nb'];
|
140 |
|
139 |
for ($i = 0; $i < $nbMotsCles; $i += $pas) {
|
141 |
for ($i = 0; $i < $nbMotsCles; $i += $pas) {
|
140 |
$requete = 'SELECT * '.
|
142 |
$requete = 'SELECT * '.
|
141 |
'FROM cel_mots_cles_'.$image_ou_obs.' '.
|
143 |
'FROM cel_mots_cles_'.$image_ou_obs.' '.
|
142 |
'ORDER BY cmc_niveau '.
|
144 |
'ORDER BY cmc_niveau '.
|
Line 143... |
Line 145... |
143 |
"LIMIT $i,$pas ";
|
145 |
"LIMIT $i,$pas ";
|
144 |
$arbres_mots_cles = $this->executerRequete($requete);
|
146 |
$arbres_mots_cles = $this->bdd->requeter($requete);
|
145 |
|
147 |
|
146 |
if (count($arbres_mots_cles) > 0) {
|
148 |
if (count($arbres_mots_cles) > 0) {
|
Line 159... |
Line 161... |
159 |
|
161 |
|
160 |
$migration = $this->executerRequeteSimple($requete);
|
162 |
$migration = $this->executerRequeteSimple($requete);
|
161 |
if (!$migration) {
|
163 |
if (!$migration) {
|
162 |
echo "La migration des mots cles $image_ou_obs a échoué ! "."\n";
|
164 |
echo "La migration des mots cles $image_ou_obs a échoué ! "."\n";
|
163 |
} else {
|
165 |
} else {
|
164 |
$this->afficherAvancement("Migration des mots clés $image_ou_obs (par $pas)");
|
166 |
$this->script->afficherAvancement("Migration des mots clés $image_ou_obs (par $pas)");
|
165 |
}
|
167 |
}
|
166 |
}
|
168 |
}
|
167 |
}
|
- |
|
168 |
}
|
- |
|
169 |
|
- |
|
170 |
/**
|
- |
|
171 |
* Utiliser cette méthode dans une boucle pour afficher un message suivi du nombre de tour de boucle effectué.
|
- |
|
172 |
* Vous devrez vous même gérer le retour à la ligne à la sortie de la boucle.
|
- |
|
173 |
*
|
- |
|
174 |
* @param string le message d'information.
|
- |
|
175 |
* @param int le nombre de départ à afficher.
|
- |
|
176 |
* @return void le message est affiché dans la console.
|
- |
|
177 |
*/
|
- |
|
178 |
protected function afficherAvancement($message, $depart = 0) {
|
- |
|
179 |
if (! isset(self::$avancement[$message])) {
|
- |
|
180 |
self::$avancement[$message] = $depart;
|
- |
|
181 |
echo "$message : ";
|
- |
|
182 |
|
- |
|
183 |
$actuel =& self::$avancement[$message];
|
169 |
}
|
184 |
echo $actuel++;
|
- |
|
185 |
} else {
|
- |
|
186 |
$actuel =& self::$avancement[$message];
|
- |
|
187 |
|
- |
|
188 |
// Cas du passage de 99 (= 2 caractères) à 100 (= 3 caractères)
|
- |
|
189 |
$passage = 0;
|
- |
|
190 |
if (strlen((string) ($actuel - 1)) < strlen((string) ($actuel))) {
|
- |
|
191 |
$passage = 1;
|
- |
|
192 |
}
|
- |
|
193 |
|
- |
|
194 |
echo str_repeat(chr(8), (strlen((string) $actuel) - $passage));
|
- |
|
195 |
echo $actuel++;
|
- |
|
196 |
}
|
170 |
echo "\n";
|
Line 197... |
Line 171... |
197 |
}
|
171 |
}
|
198 |
|
172 |
|
199 |
private function construireSousRequeteInsertionArbresMotsCles($prefixe, $ligne) {
|
173 |
private function construireSousRequeteInsertionArbresMotsCles($prefixe, $ligne) {
|
Line 200... |
Line 174... |
200 |
$id_proprietaire_mot_cle = $ligne[$prefixe.'id_proprietaire'];
|
174 |
$id_proprietaire_mot_cle = $ligne[$prefixe.'id_proprietaire'];
|
201 |
$id_proprietaire_mot_cle = $this->renvoyerIdPourMigration($id_proprietaire_mot_cle);
|
175 |
$id_proprietaire_mot_cle = $this->renvoyerIdPourMigration($id_proprietaire_mot_cle);
|
202 |
|
176 |
|
203 |
$sous_requete = '('.$this->proteger($ligne[$prefixe.'id_mot_cle_utilisateur']).','.
|
177 |
$sous_requete = '('.$this->bdd->proteger($ligne[$prefixe.'id_mot_cle_utilisateur']).','.
|
204 |
$this->proteger($id_proprietaire_mot_cle).','.
|
178 |
$this->bdd->proteger($id_proprietaire_mot_cle).','.
|
205 |
$this->proteger($ligne[$prefixe.'mot_cle']).','.
|
179 |
$this->bdd->proteger($ligne[$prefixe.'mot_cle']).','.
|
206 |
$this->proteger($ligne[$prefixe.'id_mot_cle_general']).','.
|
180 |
$this->bdd->proteger($ligne[$prefixe.'id_mot_cle_general']).','.
|
207 |
$this->proteger($ligne[$prefixe.'bg']).','.
|
181 |
$this->bdd->proteger($ligne[$prefixe.'bg']).','.
|
208 |
$this->proteger($ligne[$prefixe.'bd']).','.
|
182 |
$this->bdd->proteger($ligne[$prefixe.'bd']).','.
|
209 |
$this->proteger($ligne[$prefixe.'niveau']).','.
|
183 |
$this->bdd->proteger($ligne[$prefixe.'niveau']).','.
|
210 |
$this->proteger($ligne[$prefixe.'id_parent']).
|
184 |
$this->bdd->proteger($ligne[$prefixe.'id_parent']).
|
Line 211... |
Line 185... |
211 |
')';
|
185 |
')';
|
Line 227... |
Line 201... |
227 |
}
|
201 |
}
|
228 |
}
|
202 |
}
|
229 |
return $retour;
|
203 |
return $retour;
|
230 |
}
|
204 |
}
|
Line 231... |
Line 205... |
231 |
|
205 |
|
232 |
public function mailValide($mail) {
|
206 |
private function mailValide($mail) {
|
233 |
// vérification bidon mais ça suffit pour ici
|
207 |
// vérification bidon mais ça suffit pour ici
|
234 |
return !(strpos('@',$mail) === false);
|
208 |
return !(strpos($mail, '@') === false);
|
Line 235... |
Line 209... |
235 |
}
|
209 |
}
|
236 |
|
210 |
|
237 |
private function migrerLiaisonsMotsClesObs() {
|
211 |
private function migrerLiaisonsMotsClesObs() {
|
238 |
$requete = 'SELECT mots_cles AS mots_cles, id AS id, identifiant AS id_utilisateur '.
|
212 |
$requete = 'SELECT mots_cles AS mots_cles, id AS id, identifiant AS id_utilisateur '.
|
239 |
'FROM cel_inventory '.
|
213 |
'FROM cel_inventory '.
|
240 |
'WHERE mots_cles != "" '.
|
214 |
'WHERE mots_cles != "" '.
|
241 |
' AND mots_cles != "NULL" '.
|
215 |
' AND mots_cles != "NULL" '.
|
242 |
' AND mots_cles != "null" '.
|
216 |
' AND mots_cles != "null" '.
|
243 |
' AND mots_cles IS NOT NULL '.
|
217 |
' AND mots_cles IS NOT NULL '.
|
Line 244... |
Line 218... |
244 |
'ORDER BY identifiant ';
|
218 |
'ORDER BY identifiant ';
|
245 |
$mots_cles_obs = $this->executerRequete($requete);
|
219 |
$mots_cles_obs = $this->bdd->requeter($requete);
|
246 |
|
220 |
|
247 |
$requete = 'INSERT INTO '.self::$bdd_cel_migration.'.cel_obs_mots_cles '.
|
221 |
$requete = 'INSERT INTO '.self::$bdd_cel_migration.'.cel_obs_mots_cles '.
|
Line 248... |
Line 222... |
248 |
'(id_observation, id_mot_cle_obs, id_utilisateur) '.
|
222 |
'(id_observation, id_mot_cle_obs, id_utilisateur) '.
|
249 |
'VALUES '.
|
223 |
'VALUES '.
|
250 |
$this->construireSousRequeteInsertionLiaisons($mots_cles_obs, ';');
|
224 |
$this->construireSousRequeteInsertionLiaisons($mots_cles_obs, ';');
|
251 |
|
225 |
|
252 |
$insertion = $this->executerRequeteSimple($requete);
|
226 |
$insertion = $this->executerRequeteSimple($requete);
|
253 |
if (!$insertion) {
|
227 |
if (!$insertion) {
|
254 |
echo 'La migration des mots cles obs a échoué ! '."\n";
|
228 |
echo 'La migration des mots cles obs a échoué ! '."\n";
|
Line 255... |
Line 229... |
255 |
} else {
|
229 |
} else {
|
256 |
echo "Migration des mots cles obs : OK\n\n";
|
230 |
echo "Migration des mots cles obs : OK\n";
|
Line 263... |
Line 237... |
263 |
'WHERE ci_meta_mots_cles != "" '.
|
237 |
'WHERE ci_meta_mots_cles != "" '.
|
264 |
' AND ci_meta_mots_cles != "NULL" '.
|
238 |
' AND ci_meta_mots_cles != "NULL" '.
|
265 |
' AND ci_meta_mots_cles != "null" '.
|
239 |
' AND ci_meta_mots_cles != "null" '.
|
266 |
' AND ci_meta_mots_cles IS NOT NULL '.
|
240 |
' AND ci_meta_mots_cles IS NOT NULL '.
|
267 |
'ORDER BY ci_ce_utilisateur';
|
241 |
'ORDER BY ci_ce_utilisateur';
|
268 |
$mots_cles_images = $this->executerRequete($requete);
|
242 |
$mots_cles_images = $this->bdd->requeter($requete);
|
Line 269... |
Line 243... |
269 |
|
243 |
|
270 |
$requete = 'INSERT INTO '.self::$bdd_cel_migration.'.cel_images_mots_cles '.
|
244 |
$requete = 'INSERT INTO '.self::$bdd_cel_migration.'.cel_images_mots_cles '.
|
271 |
'(id_image, id_mot_cle_image, id_utilisateur) '.
|
245 |
'(id_image, id_mot_cle_image, id_utilisateur) '.
|
272 |
'VALUES '.
|
246 |
'VALUES '.
|
Line 275... |
Line 249... |
275 |
$insertion = $this->executerRequeteSimple($requete);
|
249 |
$insertion = $this->executerRequeteSimple($requete);
|
Line 276... |
Line 250... |
276 |
|
250 |
|
277 |
if (!$insertion) {
|
251 |
if (!$insertion) {
|
278 |
echo 'La migration des mots cles images a échoué ! '."\n";
|
252 |
echo 'La migration des mots cles images a échoué ! '."\n";
|
279 |
} else {
|
253 |
} else {
|
280 |
echo "Migration des mots cles images : OK\n\n";
|
254 |
echo "Migration des mots cles images : OK\n";
|
281 |
}
|
255 |
}
|
Line 282... |
Line 256... |
282 |
}
|
256 |
}
|
283 |
|
257 |
|
284 |
private function construireSousRequeteInsertionLiaisons($tableau_mots_cles, $separateur) {
|
258 |
private function construireSousRequeteInsertionLiaisons($tableau_mots_cles, $separateur) {
|
285 |
$sous_requete = array();
|
259 |
$sous_requete = array();
|
286 |
foreach ($tableau_mots_cles as $element) {
|
260 |
foreach ($tableau_mots_cles as $element) {
|
287 |
$mots_cles_ids = $this->parserMotsCles($element['mots_cles'], $separateur);
|
261 |
$mots_cles_ids = $this->parserMotsCles($element['mots_cles'], $separateur);
|
288 |
foreach ($mots_cles_ids as $mot_cle_id) {
|
262 |
foreach ($mots_cles_ids as $mot_cle_id) {
|
289 |
$id = $this->proteger($element['id']);
|
263 |
$id = $this->bdd->proteger($element['id']);
|
290 |
$id_mot_cle = $this->proteger($mot_cle_id);
|
264 |
$id_mot_cle = $this->bdd->proteger($mot_cle_id);
|
291 |
$id_utilisateur = $this->proteger($this->renvoyerIdPourMigration($element['id_utilisateur']));
|
265 |
$id_utilisateur = $this->bdd->proteger($this->renvoyerIdPourMigration($element['id_utilisateur']));
|
292 |
$sous_requete[] = "($id, $id_mot_cle, $id_utilisateur)";
|
266 |
$sous_requete[] = "($id, $id_mot_cle, $id_utilisateur)";
|
293 |
}
|
267 |
}
|
294 |
}
|
268 |
}
|
Line 333... |
Line 307... |
333 |
}
|
307 |
}
|
Line 334... |
Line 308... |
334 |
|
308 |
|
335 |
private function genererIndexTexteMotsClesObs() {
|
309 |
private function genererIndexTexteMotsClesObs() {
|
336 |
$requete = 'SELECT DISTINCT id_observation, id_utilisateur '.
|
310 |
$requete = 'SELECT DISTINCT id_observation, id_utilisateur '.
|
337 |
'FROM '.self::$bdd_cel_migration.'.cel_obs_mots_cles ';
|
311 |
'FROM '.self::$bdd_cel_migration.'.cel_obs_mots_cles ';
|
Line 338... |
Line 312... |
338 |
$obs_a_mots_cles = $this->requeter($requete);
|
312 |
$obs_a_mots_cles = $this->bdd->requeter($requete);
|
339 |
|
313 |
|
340 |
foreach ($obs_a_mots_cles as $obs) {
|
314 |
foreach ($obs_a_mots_cles as $obs) {
|
341 |
$mots_cles_texte = $this->obtenirMotsClesTexte($obs['id_observation'], $obs['id_utilisateur'], 'obs');
|
315 |
$mots_cles_texte = $this->obtenirMotsClesTexte($obs['id_observation'], $obs['id_utilisateur'], 'obs');
|
342 |
if (is_array($mots_cles_texte) && count($mots_cles_texte) > 0) {
|
316 |
if (is_array($mots_cles_texte) && count($mots_cles_texte) > 0) {
|
343 |
$mots_cles_texte_chaine = implode(',', $mots_cles_texte);
|
317 |
$mots_cles_texte_chaine = implode(',', $mots_cles_texte);
|
344 |
$mise_a_jour_index = $this->executerRequeteMiseAJourMotCleTexte($mots_cles_texte_chaine, $obs['id_observation'], $obs['id_utilisateur'], 'obs');
|
318 |
$mise_a_jour_index = $this->executerRequeteMiseAJourMotCleTexte($mots_cles_texte_chaine, $obs['id_observation'], $obs['id_utilisateur'], 'obs');
|
345 |
$this->afficherAvancement('Génération des index mots clés obs (par 1)');
|
319 |
$this->script->afficherAvancement('Génération des index mots clés obs (par 1)');
|
346 |
}
|
320 |
}
|
347 |
}
|
321 |
}
|
Line 348... |
Line 322... |
348 |
echo "\n-----------------------------------------------------------------OK\n";
|
322 |
echo "\n";
|
349 |
}
|
323 |
}
|
350 |
|
324 |
|
351 |
private function genererIndexTexteMotsClesImages() {
|
325 |
private function genererIndexTexteMotsClesImages() {
|
Line 352... |
Line 326... |
352 |
$requete = 'SELECT DISTINCT id_image, id_utilisateur '.
|
326 |
$requete = 'SELECT DISTINCT id_image, id_utilisateur '.
|
353 |
'FROM '.self::$bdd_cel_migration.'.cel_images_mots_cles ';
|
327 |
'FROM '.self::$bdd_cel_migration.'.cel_images_mots_cles ';
|
354 |
$images_a_mots_cles = $this->requeter($requete);
|
328 |
$images_a_mots_cles = $this->bdd->requeter($requete);
|
355 |
|
329 |
|
356 |
foreach ($images_a_mots_cles as $image) {
|
330 |
foreach ($images_a_mots_cles as $image) {
|
357 |
$mots_cles_texte = $this->obtenirMotsClesTexte($image['id_image'], $image['id_utilisateur'], 'images');
|
331 |
$mots_cles_texte = $this->obtenirMotsClesTexte($image['id_image'], $image['id_utilisateur'], 'images');
|
358 |
$mots_cles_texte_chaine = '';
|
332 |
$mots_cles_texte_chaine = '';
|
359 |
if (is_array($mots_cles_texte) && count($mots_cles_texte) > 0) {
|
333 |
if (is_array($mots_cles_texte) && count($mots_cles_texte) > 0) {
|
360 |
$mots_cles_texte_chaine = implode(',', $mots_cles_texte);
|
334 |
$mots_cles_texte_chaine = implode(',', $mots_cles_texte);
|
361 |
$mise_a_jour_index = $this->executerRequeteMiseAJourMotCleTexte($mots_cles_texte_chaine, $image['id_image'], $image['id_utilisateur'], 'images');
|
335 |
$mise_a_jour_index = $this->executerRequeteMiseAJourMotCleTexte($mots_cles_texte_chaine, $image['id_image'], $image['id_utilisateur'], 'images');
|
362 |
$this->afficherAvancement('Génération des index mots clés images (par 1)');
|
336 |
$this->script->afficherAvancement('Génération des index mots clés images (par 1)');
|
Line 363... |
Line 337... |
363 |
}
|
337 |
}
|
364 |
}
|
338 |
}
|
365 |
echo "\n-----------------------------------------------------------------OK\n";
|
339 |
echo "\n";
|
366 |
}
|
340 |
}
|
367 |
|
341 |
|
368 |
private function obtenirMotsClesTexte($id_image_ou_obs, $id_utilisateur, $mode) {
|
342 |
private function obtenirMotsClesTexte($id_image_ou_obs, $id_utilisateur, $mode) {
|
Line 369... |
Line 343... |
369 |
$bdd = self::$bdd_cel_migration;
|
343 |
$bdd = self::$bdd_cel_migration;
|
370 |
$champ_id_mot_cle = ($mode == 'obs') ? 'id_mot_cle_obs' : 'id_mot_cle_image';
|
344 |
$champ_id_mot_cle = ($mode == 'obs') ? 'id_mot_cle_obs' : 'id_mot_cle_image';
|
371 |
$champ_id_obs_ou_img = ($mode == 'obs') ? 'id_observation' : 'id_image';
|
345 |
$champ_id_obs_ou_img = ($mode == 'obs') ? 'id_observation' : 'id_image';
|
372 |
$id_image_ou_obs = $this->proteger($id_image_ou_obs);
|
346 |
$id_image_ou_obs = $this->bdd->proteger($id_image_ou_obs);
|
373 |
$id_utilisateur = $this->proteger($id_utilisateur);
|
347 |
$id_utilisateur = $this->bdd->proteger($id_utilisateur);
|
374 |
|
348 |
|
375 |
$requete = 'SELECT mot_cle '.
|
349 |
$requete = 'SELECT mot_cle '.
|
Line 376... |
Line 350... |
376 |
"FROM $bdd.cel_mots_cles_$mode AS a ".
|
350 |
"FROM $bdd.cel_mots_cles_$mode AS a ".
|
377 |
" INNER JOIN $bdd.cel_{$mode}_mots_cles AS b ".
|
351 |
" INNER JOIN $bdd.cel_{$mode}_mots_cles AS b ".
|
378 |
" ON (a.$champ_id_mot_cle = b.$champ_id_mot_cle AND a.id_utilisateur = b.id_utilisateur) ".
|
352 |
" ON (a.$champ_id_mot_cle = b.$champ_id_mot_cle AND a.id_utilisateur = b.id_utilisateur) ".
|
379 |
"WHERE b.$champ_id_obs_ou_img = $id_image_ou_obs ".
|
353 |
"WHERE b.$champ_id_obs_ou_img = $id_image_ou_obs ".
|
Line 390... |
Line 364... |
390 |
|
364 |
|
391 |
private function executerRequeteMiseAJourMotCleTexte($mots_cles_texte_chaine, $id_image_ou_obs, $id_utilisateur, $mode_image_ou_obs) {
|
365 |
private function executerRequeteMiseAJourMotCleTexte($mots_cles_texte_chaine, $id_image_ou_obs, $id_utilisateur, $mode_image_ou_obs) {
|
392 |
$bdd = self::$bdd_cel_migration;
|
366 |
$bdd = self::$bdd_cel_migration;
|
393 |
$table = ($mode_image_ou_obs == 'obs') ? 'cel_obs' : 'cel_images';
|
367 |
$table = ($mode_image_ou_obs == 'obs') ? 'cel_obs' : 'cel_images';
|
394 |
$chp_id_obs_ou_img = ($mode_image_ou_obs == 'obs') ? 'id_observation' : 'id_image';
|
368 |
$chp_id_obs_ou_img = ($mode_image_ou_obs == 'obs') ? 'id_observation' : 'id_image';
|
395 |
$id_image_ou_obs = $this->proteger($id_image_ou_obs);
|
369 |
$id_image_ou_obs = $this->bdd->proteger($id_image_ou_obs);
|
396 |
$mots_cles_texte = $this->proteger($mots_cles_texte_chaine);
|
370 |
$mots_cles_texte = $this->bdd->proteger($mots_cles_texte_chaine);
|
Line 397... |
Line 371... |
397 |
$ce_utilisateur = $this->proteger($id_utilisateur);
|
371 |
$ce_utilisateur = $this->bdd->proteger($id_utilisateur);
|
398 |
|
372 |
|
399 |
$requete = "UPDATE $bdd.$table ".
|
373 |
$requete = "UPDATE $bdd.$table ".
|
400 |
"SET mots_cles_texte = $mots_cles_texte ".
|
374 |
"SET mots_cles_texte = $mots_cles_texte ".
|
Line 401... |
Line 375... |
401 |
"WHERE $chp_id_obs_ou_img = $id_image_ou_obs ".
|
375 |
"WHERE $chp_id_obs_ou_img = $id_image_ou_obs ".
|
402 |
" AND ce_utilisateur = $id_utilisateur ";
|
376 |
" AND ce_utilisateur = $ce_utilisateur ";
|
Line 403... |
Line 377... |
403 |
|
377 |
|
404 |
return $this->executer($requete);
|
378 |
return $this->bdd->executer($requete);
|
405 |
}
|
379 |
}
|
Line 406... |
Line 380... |
406 |
|
380 |
|
407 |
private function mettreANullMotsClesTxtVide() {
|
381 |
private function mettreANullMotsClesTxtVide() {
|
408 |
$bdd = self::$bdd_cel_migration;
|
382 |
$bdd = self::$bdd_cel_migration;
|
409 |
$tables = array('cel_obs', 'cel_images');
|
383 |
$tables = array('cel_obs', 'cel_images');
|
410 |
|
384 |
|
411 |
foreach ($tables as $table) {
|
385 |
foreach ($tables as $table) {
|
412 |
$requete = "UPDATE $bdd.$table ".
|
386 |
$requete = "UPDATE $bdd.$table ".
|
413 |
'SET mots_cles_texte = NULL '.
|
387 |
'SET mots_cles_texte = NULL '.
|
414 |
"WHERE mots_cles_texte = '' ";
|
388 |
"WHERE mots_cles_texte = '' ";
|