Subversion Repositories eFlore/Projets.eflore-projets

Rev

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