292 |
jpm |
1 |
<?php
|
|
|
2 |
//declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Exemple de lancement du script : :
|
|
|
5 |
* /opt/lampp/bin/php cli.php coste -a chargerTous
|
|
|
6 |
*
|
|
|
7 |
* @category php 5.2
|
|
|
8 |
* @package eFlore/Scripts
|
|
|
9 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
10 |
* @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.gnu.org/licenses/gpl.html Licence GNU-GPL
|
|
|
13 |
* @version $Id$
|
|
|
14 |
*/
|
|
|
15 |
class Coste extends EfloreScript {
|
|
|
16 |
|
|
|
17 |
public function executer() {
|
|
|
18 |
try {
|
|
|
19 |
$this->initialiserProjet('coste');
|
|
|
20 |
|
|
|
21 |
// Lancement de l'action demandée
|
|
|
22 |
$cmd = $this->getParametre('a');
|
|
|
23 |
switch ($cmd) {
|
|
|
24 |
case 'chargerTous' :
|
|
|
25 |
$this->chargerStructureSql();
|
|
|
26 |
$this->chargerVersions();
|
|
|
27 |
break;
|
|
|
28 |
case 'chargerStructureSql' :
|
|
|
29 |
$this->chargerStructureSql();
|
|
|
30 |
break;
|
|
|
31 |
case 'chargerVersions' :
|
|
|
32 |
$this->chargerVersions();
|
|
|
33 |
break;
|
|
|
34 |
case 'supprimerTous' :
|
|
|
35 |
$this->supprimerTous();
|
|
|
36 |
break;
|
|
|
37 |
case 'creerV1' :
|
|
|
38 |
$this->creerVersion1();
|
|
|
39 |
break;
|
|
|
40 |
case 'nettoyerV1' :
|
|
|
41 |
$this->nettoyerVersion1();
|
|
|
42 |
break;
|
|
|
43 |
default :
|
|
|
44 |
throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
|
|
|
45 |
}
|
|
|
46 |
} catch (Exception $e) {
|
|
|
47 |
$this->traiterErreur($e->getMessage());
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
private function chargerVersions() {
|
|
|
52 |
$versions = explode(',', Config::get('versions'));
|
|
|
53 |
$versionsDonnees = explode(',', Config::get('versionsDonnees'));
|
|
|
54 |
foreach ($versions as $id => $version) {
|
|
|
55 |
$versionDonnees = $versionsDonnees[$id];
|
|
|
56 |
$this->chargerStructureSqlVersion($versionDonnees, $version);
|
|
|
57 |
$this->chargerIndexVersion($versionDonnees, $version);
|
|
|
58 |
$this->chargerDumpWikiniVersion($versionDonnees, $version);
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
private function chargerStructureSqlVersion($versionDonnees, $version) {
|
|
|
63 |
$fichierSqlTpl = Config::get('chemins.structureSqlVersionTpl');
|
|
|
64 |
$fichierSql = sprintf($fichierSqlTpl, $versionDonnees, $version);
|
|
|
65 |
$contenuSql = $this->recupererContenu($fichierSql);
|
|
|
66 |
$this->executerScripSql($contenuSql);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
private function chargerIndexVersion($versionDonnees, $version) {
|
|
|
70 |
$fichierTsvTpl = Config::get('chemins.costeTpl');
|
|
|
71 |
$fichierTsv = sprintf($fichierTsvTpl, $versionDonnees, $version);
|
|
|
72 |
$tableTpl = Config::get('tables.costeTpl');
|
|
|
73 |
$table = sprintf($tableTpl, $version);
|
|
|
74 |
$requete = "LOAD DATA INFILE '$fichierTsv' ".
|
|
|
75 |
"REPLACE INTO TABLE $table ".
|
|
|
76 |
'CHARACTER SET utf8 '.
|
|
|
77 |
'FIELDS '.
|
|
|
78 |
" TERMINATED BY '\t' ".
|
|
|
79 |
" ENCLOSED BY '' ".
|
|
|
80 |
" ESCAPED BY '\\\' ".
|
|
|
81 |
'IGNORE 1 LINES ';
|
|
|
82 |
$this->getBdd()->requeter($requete);
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
private function chargerDumpWikiniVersion($versionDonnees, $version) {
|
|
|
86 |
$fichierWikiTpl = Config::get('chemins.costeWikiniTpl');
|
|
|
87 |
$fichierDump = sprintf($fichierWikiTpl, $versionDonnees, $version);
|
|
|
88 |
$contenuSql = $this->recupererContenu($fichierDump);
|
|
|
89 |
$this->executerScripSql($contenuSql);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
private function supprimerTous() {
|
351 |
jpm |
93 |
$requete = "DROP TABLE IF EXISTS coste_meta, ".
|
292 |
jpm |
94 |
" coste_acls, coste_links, coste_pages, coste_referrers, coste_triples, coste_users, ".
|
|
|
95 |
" coste_v1_00 ";
|
|
|
96 |
$this->getBdd()->requeter($requete);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
private function nettoyerVersion1() {
|
351 |
jpm |
100 |
$requete = "DROP TABLE IF EXISTS coste_correspondance_bdnff, coste_images_auteur_correspondance_bdnff, ".
|
292 |
jpm |
101 |
" coste_images_correspondance_bdnff, coste_index, coste_index_general";
|
|
|
102 |
$this->getBdd()->requeter($requete);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
private function creerVersion1() {
|
|
|
106 |
$this->chargerStructureSqlVersion('0.00', '0_00');
|
|
|
107 |
$this->chargerCosteImagesAuteurCorrespondanceBdnff();
|
|
|
108 |
$this->chargerCosteCorrespondanceBdnff();
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
private function chargerCosteImagesAuteurCorrespondanceBdnff() {
|
|
|
112 |
$fichierTsv = sprintf(Config::get('dossierTsvTpl'), '0.00').'coste_images_auteur_correspondance_bdnff.tsv';
|
|
|
113 |
$requete = "LOAD DATA INFILE '$fichierTsv' ".
|
|
|
114 |
"REPLACE INTO TABLE coste_images_auteur_correspondance_bdnff ".
|
|
|
115 |
'CHARACTER SET utf8 '.
|
|
|
116 |
'FIELDS '.
|
|
|
117 |
" TERMINATED BY '\t' ".
|
|
|
118 |
" ENCLOSED BY '\"' ".
|
|
|
119 |
" ESCAPED BY '\\\' ".
|
|
|
120 |
'IGNORE 1 LINES ';
|
|
|
121 |
$this->getBdd()->requeter($requete);
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
private function chargerCosteCorrespondanceBdnff() {
|
|
|
125 |
$fichierTsv = sprintf(Config::get('dossierTsvTpl'), '0.00').'coste_images_correspondance_bdnff.tsv';
|
|
|
126 |
$requete = "LOAD DATA INFILE '$fichierTsv' ".
|
|
|
127 |
"REPLACE INTO TABLE coste_images_correspondance_bdnff ".
|
|
|
128 |
'CHARACTER SET utf8 '.
|
|
|
129 |
'FIELDS '.
|
|
|
130 |
" TERMINATED BY '\t' ".
|
|
|
131 |
" ENCLOSED BY '' ".
|
|
|
132 |
" ESCAPED BY '\\\' ".
|
|
|
133 |
'IGNORE 1 LINES ';
|
|
|
134 |
$this->getBdd()->requeter($requete);
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
?>
|