Subversion Repositories eFlore/Projets.eflore-projets

Rev

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