Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 477 | Rev 479 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 477 Rev 478
1
<?php
1
<?php
2
//declare(encoding='UTF-8');
2
//declare(encoding='UTF-8');
3
/**
3
/**
4
 * Exemple de lancement du script : :
4
 * Exemple de lancement du script : :
5
 * /opt/lampp/bin/php cli.php coste -a chargerTous
5
 * /opt/lampp/bin/php cli.php coste -a chargerTous
6
 *
6
 *
7
 * @category	php 5.2
7
 * @category	php 5.2
8
 * @package		eFlore/Scripts
8
 * @package		eFlore/Scripts
9
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
 * @copyright	Copyright (c) 2012, Tela Botanica (accueil@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
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
12
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
13
 * @version		$Id$
13
 * @version		$Id$
14
 */
14
 */
15
class Coste extends EfloreScript {
15
class Coste extends EfloreScript {
16
 
16
 
17
	public function executer() {
17
	public function executer() {
18
		try {
18
		try {
19
			$this->initialiserProjet('coste');
19
			$this->initialiserProjet('coste');
20
 
20
 
21
			// Lancement de l'action demandée
21
			// Lancement de l'action demandée
22
			$cmd = $this->getParametre('a');
22
			$cmd = $this->getParametre('a');
23
			switch ($cmd) {
23
			switch ($cmd) {
24
				case 'chargerTous' :
24
				case 'chargerTous' :
25
					$this->chargerStructureSql();
25
					$version = $this->getClasseVersion();
26
					$this->chargerVersions();
26
					$version->chargerTous();
27
					break;
27
					break;
28
				case 'chargerStructureSql' :
28
				case 'chargerStructureSql' :
-
 
29
					$version = $this->getClasseVersion();
29
					$this->chargerStructureSql();
30
					$version->chargerStructureSql();
30
					break;
31
					break;
31
				case 'chargerVersions' :
32
				case 'chargerVersions' :
-
 
33
					$version = $this->getClasseVersion();
32
					$this->chargerVersions();
34
					$version->chargerVersions();
33
					break;
35
					break;
34
				case 'supprimerTous' :
36
				case 'supprimerTous' :
-
 
37
					$version = $this->getClasseVersion();
35
					$this->supprimerTous();
38
					$version->supprimerTous();
36
					break;
39
					break;
37
				case 'creerV1' :
40
				case 'creerV1' :
-
 
41
					$version = $this->getClasseVersion();
38
					$this->creerVersion1();
42
					$version->creerVersion1();
39
					break;
43
					break;
40
				case 'nettoyerV1' :
44
				case 'nettoyerV1' :
-
 
45
					$version = $this->getClasseVersion();
41
					$this->nettoyerVersion1();
46
					$version->nettoyerVersion1();
42
					break;
47
					break;
43
				case 'creerDscTxt' :
48
				case 'creerDscTxt' :
-
 
49
					$description = $this->getClasseDescription();
44
					$this->creerDescriptionTxt();
50
					$description->genererDescriptionTxt();
45
					break;
51
					break;
46
				case 'statDscTxt' :
52
				case 'statDscTxt' :
-
 
53
					$description = $this->getClasseDescription();
47
					$this->verifierDescriptionTxt();
54
					$description->verifierDescriptionTxt();
48
					break;
55
					break;
49
				case 'correspondanceDsc' :
56
				case 'correspondanceDsc' :
-
 
57
					$description = $this->getClasseDescription();
50
					$this->genererCorrespondanceDescription();
58
					$description->genererCorrespondance();
51
					break;
59
					break;
52
				case 'fusionIndex' :
60
				case 'fusionIndex' :
-
 
61
					$description = $this->getClasseIndex();
53
					$this->fusionnerIndex();
62
					$description->fusionnerIndex();
54
					break;
63
					break;
55
				case 'uploadFichiersSp' :
64
				case 'uploadFichiersSp' :
-
 
65
					$wiki = $this->getClasseWiki();
56
					$this->uploaderFichiersSp();
66
					$wiki->uploaderFichiersSp();
57
					break;
67
					break;
58
				case 'downloadWiki' :
68
				case 'downloadWiki' :
-
 
69
					$wiki = $this->getClasseWiki();
59
					$this->dowloaderWiki();
70
					$wiki->dowloaderPagesWiki();
-
 
71
					break;
-
 
72
				case 'uploadEflore' :
-
 
73
					$wiki = $this->getClasseWiki();
-
 
74
					$wiki->uploaderDansWikiEflore();
60
					break;
75
					break;
61
				default :
76
				default :
62
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
77
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
63
			}
78
			}
64
		} catch (Exception $e) {
79
		} catch (Exception $e) {
65
			$this->traiterErreur($e->getMessage());
80
			$this->traiterErreur($e->getMessage());
66
		}
81
		}
67
	}
82
	}
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() {
-
 
111
		$requete = "DROP TABLE IF EXISTS coste_meta, ".
-
 
112
			"	coste_acls, coste_links, coste_pages, coste_referrers, coste_triples, coste_users, ".
-
 
113
			"	coste_v1_00 ";
-
 
114
		$this->getBdd()->requeter($requete);
-
 
115
	}
-
 
116
 
83
 
117
	private function nettoyerVersion1() {
-
 
118
		$requete = "DROP TABLE IF EXISTS coste_correspondance_bdnff, coste_images_auteur_correspondance_bdnff, ".
-
 
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
	}
-
 
154
 
-
 
155
	private function creerDescriptionTxt() {
-
 
156
		$description = $this->getClasseDescription();
-
 
157
		$description->genererDescriptionTxt();
-
 
158
	}
-
 
159
 
-
 
160
	private function verifierDescriptionTxt() {
84
	private function getClasseVersion($version = '1') {
161
		$description = $this->getClasseDescription();
85
		$version1 = $this->getClasse('Version');
162
		$description->verifierDescriptionTxt();
-
 
163
	}
-
 
164
 
-
 
165
	private function genererCorrespondanceDescription() {
-
 
166
		$description = $this->getClasseDescription();
-
 
167
		$description->genererCorrespondance();
86
		return $version1;
168
	}
87
	}
169
 
88
 
170
	private function getClasseDescription() {
89
	private function getClasseDescription() {
171
		$description = $this->getClasse('Description');
90
		$description = $this->getClasse('Description');
172
		return $description;
91
		return $description;
173
	}
92
	}
174
 
-
 
175
	private function fusionnerIndex() {
-
 
176
		$description = $this->getClasseIndex();
-
 
177
		$description->fusionnerIndex();
-
 
178
	}
-
 
179
 
93
 
180
	private function getClasseIndex() {
94
	private function getClasseIndex() {
181
		$index = $this->getClasse('Index');
95
		$index = $this->getClasse('Index');
182
		return $index;
96
		return $index;
183
	}
97
	}
184
 
-
 
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
 
98
 
195
	private function getClasseWiki() {
99
	private function getClasseWiki() {
196
		$wiki = $this->getClasse('Wiki');
100
		$wiki = $this->getClasse('Wiki');
197
		return $wiki;
101
		return $wiki;
198
	}
102
	}
199
 
103
 
200
	private function getClasse($classeNom) {
104
	private function getClasse($classeNom) {
201
		$conteneur = new Conteneur();
105
		$conteneur = new Conteneur();
202
		$conteneur->setParametre('-v', $this->getParametre('-v'));
106
		$conteneur->setParametre('-v', $this->getParametre('-v'));
-
 
107
		$conteneur->setParametre('scriptChemin', $this->getScriptChemin());
203
		require_once dirname(__FILE__).'/'.$classeNom.'.php';
108
		require_once dirname(__FILE__).'/'.$classeNom.'.php';
204
		$objet = new $classeNom($conteneur);
109
		$objet = new $classeNom($conteneur);
205
		return $objet;
110
		return $objet;
206
	}
111
	}
207
}
112
}
208
?>
113
?>