Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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