Subversion Repositories eFlore/Projets.eflore-projets

Rev

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