Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 428 | Rev 477 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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;
424 jpm 43
				case 'creerDscTxt' :
44
					$this->creerDescriptionTxt();
45
					break;
428 jpm 46
				case 'statDscTxt' :
47
					$this->verifierDescriptionTxt();
48
					break;
49
				case 'correspondanceDsc' :
50
					$this->genererCorrespondanceDescription();
51
					break;
469 jpm 52
				case 'fusionIndex' :
53
					$this->fusionnerIndex();
54
					break;
292 jpm 55
				default :
56
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
57
			}
58
		} catch (Exception $e) {
59
			$this->traiterErreur($e->getMessage());
60
		}
61
	}
62
 
63
	private function chargerVersions() {
64
		$versions = explode(',', Config::get('versions'));
65
		$versionsDonnees = explode(',', Config::get('versionsDonnees'));
66
		foreach ($versions as $id => $version) {
67
			$versionDonnees = $versionsDonnees[$id];
68
			$this->chargerStructureSqlVersion($versionDonnees, $version);
69
			$this->chargerIndexVersion($versionDonnees, $version);
70
			$this->chargerDumpWikiniVersion($versionDonnees, $version);
71
		}
72
	}
73
 
74
	private function chargerStructureSqlVersion($versionDonnees, $version) {
75
		$fichierSqlTpl = Config::get('chemins.structureSqlVersionTpl');
76
		$fichierSql = sprintf($fichierSqlTpl, $versionDonnees, $version);
77
		$contenuSql = $this->recupererContenu($fichierSql);
78
		$this->executerScripSql($contenuSql);
79
	}
80
 
81
	private function chargerIndexVersion($versionDonnees, $version) {
82
		$fichierTsvTpl = Config::get('chemins.costeTpl');
83
		$fichierTsv = sprintf($fichierTsvTpl, $versionDonnees, $version);
84
		$tableTpl = Config::get('tables.costeTpl');
85
		$table = sprintf($tableTpl, $version);
86
		$requete = "LOAD DATA INFILE '$fichierTsv' ".
87
			"REPLACE INTO TABLE $table ".
88
			'CHARACTER SET utf8 '.
89
			'FIELDS '.
90
			"	TERMINATED BY '\t' ".
91
			"	ENCLOSED BY '' ".
92
			"	ESCAPED BY '\\\' ".
93
			'IGNORE 1 LINES ';
94
		$this->getBdd()->requeter($requete);
95
	}
96
 
97
	private function chargerDumpWikiniVersion($versionDonnees, $version) {
98
		$fichierWikiTpl = Config::get('chemins.costeWikiniTpl');
99
		$fichierDump = sprintf($fichierWikiTpl, $versionDonnees, $version);
100
		$contenuSql = $this->recupererContenu($fichierDump);
101
		$this->executerScripSql($contenuSql);
102
	}
103
 
104
	private function supprimerTous() {
351 jpm 105
		$requete = "DROP TABLE IF EXISTS coste_meta, ".
292 jpm 106
			"	coste_acls, coste_links, coste_pages, coste_referrers, coste_triples, coste_users, ".
107
			"	coste_v1_00 ";
108
		$this->getBdd()->requeter($requete);
109
	}
110
 
111
	private function nettoyerVersion1() {
351 jpm 112
		$requete = "DROP TABLE IF EXISTS coste_correspondance_bdnff, coste_images_auteur_correspondance_bdnff, ".
292 jpm 113
			"	coste_images_correspondance_bdnff, coste_index, coste_index_general";
114
		$this->getBdd()->requeter($requete);
115
	}
116
 
117
	private function creerVersion1() {
118
		$this->chargerStructureSqlVersion('0.00', '0_00');
119
		$this->chargerCosteImagesAuteurCorrespondanceBdnff();
120
		$this->chargerCosteCorrespondanceBdnff();
121
	}
122
 
123
	private function chargerCosteImagesAuteurCorrespondanceBdnff() {
124
		$fichierTsv = sprintf(Config::get('dossierTsvTpl'), '0.00').'coste_images_auteur_correspondance_bdnff.tsv';
125
		$requete = "LOAD DATA INFILE '$fichierTsv' ".
126
				"REPLACE INTO TABLE coste_images_auteur_correspondance_bdnff ".
127
				'CHARACTER SET utf8 '.
128
				'FIELDS '.
129
				"	TERMINATED BY '\t' ".
130
				"	ENCLOSED BY '\"' ".
131
				"	ESCAPED BY '\\\' ".
132
				'IGNORE 1 LINES ';
133
		$this->getBdd()->requeter($requete);
134
	}
135
 
136
	private function chargerCosteCorrespondanceBdnff() {
137
		$fichierTsv = sprintf(Config::get('dossierTsvTpl'), '0.00').'coste_images_correspondance_bdnff.tsv';
138
		$requete = "LOAD DATA INFILE '$fichierTsv' ".
139
					"REPLACE INTO TABLE coste_images_correspondance_bdnff ".
140
					'CHARACTER SET utf8 '.
141
					'FIELDS '.
142
					"	TERMINATED BY '\t' ".
143
					"	ENCLOSED BY '' ".
144
					"	ESCAPED BY '\\\' ".
145
					'IGNORE 1 LINES ';
146
		$this->getBdd()->requeter($requete);
147
	}
424 jpm 148
 
149
	private function creerDescriptionTxt() {
428 jpm 150
		$description = $this->getClasseDescription();
424 jpm 151
		$description->genererDescriptionTxt();
152
	}
428 jpm 153
 
154
	private function verifierDescriptionTxt() {
155
		$description = $this->getClasseDescription();
156
		$description->verifierDescriptionTxt();
157
	}
158
 
159
	private function genererCorrespondanceDescription() {
160
		$description = $this->getClasseDescription();
161
		$description->genererCorrespondance();
162
	}
163
 
469 jpm 164
	private function getClasseDescription() {
165
		$description = $this->getClasse('Description');
166
		return $description;
167
	}
168
 
169
	private function fusionnerIndex() {
170
		$description = $this->getClasseIndex();
171
		$description->fusionnerIndex();
172
	}
173
 
174
	private function getClasseIndex() {
175
		$index = $this->getClasse('Index');
176
		return $index;
177
	}
178
 
179
	private function getClasse($classeNom) {
428 jpm 180
		$conteneur = new Conteneur();
181
		$conteneur->setParametre('-v', $this->getParametre('-v'));
469 jpm 182
		require_once dirname(__FILE__).'/'.$classeNom.'.php';
183
		$objet = new $classeNom($conteneur);
184
		return $objet;
428 jpm 185
	}
292 jpm 186
}
187
?>