710 |
delphine |
1 |
<?php
|
775 |
delphine |
2 |
/** Corriger les codes langues pays genre et nombre à la main
|
|
|
3 |
* Exemple lancement:
|
722 |
aurelien |
4 |
* /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php nva -a chargerTous
|
710 |
delphine |
5 |
*/
|
|
|
6 |
class Nva extends EfloreScript {
|
722 |
aurelien |
7 |
|
710 |
delphine |
8 |
public function executer() {
|
|
|
9 |
// Lancement de l'action demandée
|
|
|
10 |
try {
|
|
|
11 |
$this->initialiserProjet('nva');
|
|
|
12 |
|
|
|
13 |
$cmd = $this->getParametre('a');
|
|
|
14 |
switch ($cmd) {
|
|
|
15 |
case 'chargerTous' :
|
|
|
16 |
$this->chargerStructureSql();
|
775 |
delphine |
17 |
$this->chargerDonnees(Config::get('chemins.nva'), Config::get('tables.nva'));
|
|
|
18 |
$this->chargerDonnees(Config::get('chemins.index'), Config::get('tables.index'));
|
|
|
19 |
$this->ajouterChampNomVernaIndex();
|
|
|
20 |
$this->chargerDonnees(Config::get('chemins.ontologies'), Config::get('tables.ontologies'));
|
710 |
delphine |
21 |
break;
|
|
|
22 |
case 'chargerStructureSql' :
|
|
|
23 |
$this->chargerStructureSql();
|
|
|
24 |
break;
|
|
|
25 |
case 'chargerDonnees' :
|
722 |
aurelien |
26 |
$this->chargerDonnees();
|
710 |
delphine |
27 |
break;
|
775 |
delphine |
28 |
case 'ajouterChampNomVernaIndex' :
|
|
|
29 |
$this->ajouterChampNomVernaIndex();
|
722 |
aurelien |
30 |
break;
|
710 |
delphine |
31 |
case 'supprimerTous' :
|
|
|
32 |
$this->supprimerTous();
|
|
|
33 |
break;
|
|
|
34 |
default :
|
|
|
35 |
throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
|
|
|
36 |
}
|
|
|
37 |
} catch (Exception $e) {
|
|
|
38 |
$this->traiterErreur($e->getMessage());
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
|
775 |
delphine |
42 |
private function chargerDonnees($chemin, $table) {
|
710 |
delphine |
43 |
$requete = "LOAD DATA INFILE '$chemin' ".
|
|
|
44 |
"REPLACE INTO TABLE $table ".
|
|
|
45 |
'CHARACTER SET utf8 '.
|
|
|
46 |
'FIELDS '.
|
|
|
47 |
" TERMINATED BY '\t' ".
|
|
|
48 |
" ENCLOSED BY '' ".
|
|
|
49 |
" ESCAPED BY '\\\' ".
|
|
|
50 |
'IGNORE 1 LINES';
|
|
|
51 |
$this->getBdd()->requeter($requete);
|
|
|
52 |
}
|
|
|
53 |
|
775 |
delphine |
54 |
private function ajouterChampNomVernaIndex() {
|
|
|
55 |
$this->preparerTablePrChpNomVerna();
|
|
|
56 |
$this->remplirChpNomVerna();
|
722 |
aurelien |
57 |
}
|
|
|
58 |
|
775 |
delphine |
59 |
private function preparerTablePrChpNomVerna() {
|
|
|
60 |
$table = Config::get('tables.index');
|
|
|
61 |
$requete = "SHOW COLUMNS FROM $table LIKE 'nom_vernaculaire' ";
|
722 |
aurelien |
62 |
$resultat = $this->getBdd()->recuperer($requete);
|
|
|
63 |
if ($resultat === false) {
|
|
|
64 |
$requete = "ALTER TABLE $table ".
|
775 |
delphine |
65 |
'ADD `nom_vernaculaire` VARCHAR( 40 ) NOT NULL ,
|
|
|
66 |
ADD `code_langue` VARCHAR( 10 ) NOT NULL ,
|
|
|
67 |
ADD `num_genre` INT( 1 ), ADD `num_nombre` INT( 1 ) ';
|
722 |
aurelien |
68 |
$this->getBdd()->requeter($requete);
|
|
|
69 |
}
|
|
|
70 |
}
|
775 |
delphine |
71 |
|
722 |
aurelien |
72 |
|
775 |
delphine |
73 |
private function remplirChpNomVerna() {
|
|
|
74 |
$table = Config::get('tables.index');
|
|
|
75 |
$requete = "UPDATE `nva_index_v2_03`
|
|
|
76 |
SET nom_vernaculaire=(select n.nom_vernaculaire from nva_v2_03 n where n.num_nom_vernaculaire=nva_index_v2_03.num_nom_vernaculaire),
|
|
|
77 |
code_langue=(select n.code_langue from nva_v2_03 n where n.num_nom_vernaculaire=nva_index_v2_03.num_nom_vernaculaire),
|
|
|
78 |
num_genre=(select n.num_genre from nva_v2_03 n where n.num_nom_vernaculaire=nva_index_v2_03.num_nom_vernaculaire),
|
|
|
79 |
num_nombre=(select n.num_nombre from nva_v2_03 n where n.num_nom_vernaculaire=nva_index_v2_03.num_nom_vernaculaire)";
|
|
|
80 |
$resultat = $this->getBdd()->requeter($requete);
|
|
|
81 |
if ($resultat === false) {
|
|
|
82 |
throw new Exception("Erreur d'update d'ajouts des noms");
|
722 |
aurelien |
83 |
}
|
775 |
delphine |
84 |
$this->afficherAvancement("Ajout des noms vernaculaires à l'index");
|
722 |
aurelien |
85 |
echo "\n";
|
|
|
86 |
}
|
|
|
87 |
|
710 |
delphine |
88 |
|
775 |
delphine |
89 |
|
|
|
90 |
|
710 |
delphine |
91 |
private function supprimerTous() {
|
775 |
delphine |
92 |
$requete = "DROP TABLE IF EXISTS ".Config::get('tables.nva').", ".Config::get('tables.index').
|
|
|
93 |
", ".Config::get('tables.ontologies').", nva_meta ";
|
710 |
delphine |
94 |
$this->getBdd()->requeter($requete);
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
?>
|