Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 54 | Rev 103 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 54 Rev 68
Line 11... Line 11...
11
 * @copyright	Copyright (c) 2011, Tela Botanica (accueil@tela-botanica.org)
11
 * @copyright	Copyright (c) 2011, Tela Botanica (accueil@tela-botanica.org)
12
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
12
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
13
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
13
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
14
 * @version		$Id$
14
 * @version		$Id$
15
 */
15
 */
16
class Bdtfx extends Script {
16
class Bdtfx extends EfloreScript {
Line 17... Line -...
17
 
-
 
18
	protected $bdd = null;
17
 
19
	protected $table = null;
-
 
20
	private $projetNom = 'bdtfx';
-
 
21
 
18
	private $table = null;
22
	protected $pasInsertion = 1000;
19
	private $pasInsertion = 1000;
Line 23... Line 20...
23
	protected $departInsertion = 0;
20
	private $departInsertion = 0;
24
 
21
 
Line 25... Line 22...
25
	protected $parametres_autorises = array(
22
	protected $parametres_autorises = array(
26
		'-t' => array(false, true, 'Permet de tester le script sur un jeux réduit de données (indiquer le nombre de lignes).'));
23
		'-t' => array(false, true, 'Permet de tester le script sur un jeux réduit de données (indiquer le nombre de lignes).'));
27
 
24
 
Line 28... Line 25...
28
	public function executer() {
25
	public function executer() {
29
		try {
26
		try {
30
			$this->initialiser();
27
			$this->initialiserProjet('bdtfx');
31
 
28
 
Line 52... Line 49...
52
		} catch (Exception $e) {
49
		} catch (Exception $e) {
53
			$this->traiterErreur($e->getMessage());
50
			$this->traiterErreur($e->getMessage());
54
		}
51
		}
55
	}
52
	}
Line 56... Line -...
56
 
-
 
57
	private function initialiser() {
-
 
58
		$this->chargerConfigDuProjet();
-
 
59
		$this->bdd = new Bdd();
-
 
60
	}
-
 
61
 
-
 
62
	private function chargerConfigDuProjet() {
-
 
63
		$fichierIni = dirname(__FILE__).DS.$this->projetNom.'.ini';
-
 
64
		if (file_exists($fichierIni)) {
-
 
65
			Config::charger($fichierIni);
-
 
66
		} else {
-
 
67
			$m = "Veuillez configurer le projet en créant le fichier '{$this->projetNom}.ini' ".
-
 
68
				"dans le dossier du module de script du projet à partir du fichier '{$this->projetNom}.defaut.ini'.";
-
 
69
			throw new Exception($m);
-
 
70
		}
-
 
71
	}
-
 
72
 
-
 
73
	private function chargerStructureSql() {
-
 
74
		$chemin = Config::get('chemins.structureSql');
-
 
75
		$requetes = Outils::extraireRequetes($chemin);
-
 
76
		foreach ($requetes as $requete) {
-
 
77
			$this->bdd->requeter($requete);
-
 
78
		}
-
 
79
	}
-
 
80
 
53
 
81
	private function chargerBdtfx() {
54
	private function chargerBdtfx() {
82
		$chemin = Config::get('chemins.bdtfx');
55
		$chemin = Config::get('chemins.bdtfx');
83
		$table = Config::get('tables.bdtfx');
56
		$table = Config::get('tables.bdtfx');
84
		$requete = "LOAD DATA INFILE '$chemin' ".
57
		$requete = "LOAD DATA INFILE '$chemin' ".
Line 87... Line 60...
87
				'FIELDS '.
60
				'FIELDS '.
88
				"	TERMINATED BY '\t' ".
61
				"	TERMINATED BY '\t' ".
89
				"	ENCLOSED BY '' ".
62
				"	ENCLOSED BY '' ".
90
				"	ESCAPED BY '\\\' ".
63
				"	ESCAPED BY '\\\' ".
91
				'IGNORE 1 LINES';
64
				'IGNORE 1 LINES';
92
		$this->bdd->requeter($requete);
65
		$this->getBdd()->requeter($requete);
93
	}
66
	}
Line 94... Line 67...
94
 
67
 
95
	private function genererNomSciHtml() {
68
	private function genererNomSciHtml() {
96
		$this->initialiserGenerationNomsSciHtml();
69
		$this->initialiserGenerationNomsSciHtml();
Line 101... Line 74...
101
			$resultat = $this->recupererTuples();
74
			$resultat = $this->recupererTuples();
102
			$nomsSciEnHtml = $generateur->generer($resultat);
75
			$nomsSciEnHtml = $generateur->generer($resultat);
103
			$this->lancerRequeteModification($nomsSciEnHtml);
76
			$this->lancerRequeteModification($nomsSciEnHtml);
104
			$this->departInsertion += $this->pasInsertion;
77
			$this->departInsertion += $this->pasInsertion;
105
			$this->afficherAvancement("Insertion des noms scientifique au format HTML dans la base par paquet de {$this->pasInsertion} en cours");
78
			$this->afficherAvancement("Insertion des noms scientifique au format HTML dans la base par paquet de {$this->pasInsertion} en cours");
106
			if ($this->stopperLaBoucle()) {
79
			if ($this->stopperLaBoucle($this->getParametre('t'))) break;
107
				break;
-
 
108
			}
-
 
109
		}
80
		}
110
		echo "\n";
81
		echo "\n";
111
	}
82
	}
Line 112... Line 83...
112
 
83
 
113
	private function initialiserGenerationNomsSciHtml() {
84
	private function initialiserGenerationNomsSciHtml() {
114
		$this->table = Config::get('tables.bdtfx');
85
		$this->table = Config::get('tables.bdtfx');
Line 115... Line 86...
115
	}
86
	}
116
 
87
 
117
	private function preparerTable() {
88
	private function preparerTable() {
118
		$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'nom_sci_html' ";
89
		$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'nom_sci_html' ";
119
		$resultat = $this->bdd->recuperer($requete);
90
		$resultat = $this->getBdd()->recuperer($requete);
120
		if ($resultat === false) {
91
		if ($resultat === false) {
121
			$requete = 	"ALTER TABLE {$this->table} ".
92
			$requete = 	"ALTER TABLE {$this->table} ".
122
							'ADD nom_sci_html VARCHAR( 500 ) '.
93
							'ADD nom_sci_html VARCHAR( 500 ) '.
123
							'CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ';
94
							'CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ';
124
			$this->bdd->requeter($requete);
95
			$this->getBdd()->requeter($requete);
Line 125... Line 96...
125
		}
96
		}
126
	}
97
	}
127
 
98
 
128
	private function recupererNbTotalTuples(){
99
	private function recupererNbTotalTuples(){
129
		$requete = "SELECT count(*) AS nb FROM {$this->table} ";
100
		$requete = "SELECT count(*) AS nb FROM {$this->table} ";
Line 130... Line 101...
130
		$resultat = $this->bdd->recuperer($requete);
101
		$resultat = $this->getBdd()->recuperer($requete);
131
		return $resultat['nb'];
102
		return $resultat['nb'];
132
	}
103
	}
133
 
104
 
134
	private function recupererTuples() {
105
	private function recupererTuples() {
135
		$requete = 'SELECT 	num_nom, rang, nom_supra_generique, genre, epithete_infra_generique, '.
106
		$requete = 'SELECT 	num_nom, rang, nom_supra_generique, genre, epithete_infra_generique, '.
136
					'	epithete_sp, type_epithete, epithete_infra_sp,cultivar_groupe, '.
107
					'	epithete_sp, type_epithete, epithete_infra_sp,cultivar_groupe, '.
137
					'	nom_commercial, cultivar '.
108
					'	nom_commercial, cultivar '.
138
					"FROM {$this->table} ".
109
					"FROM {$this->table} ".
Line 139... Line 110...
139
					"LIMIT {$this->departInsertion},{$this->pasInsertion} ";
110
					"LIMIT {$this->departInsertion},{$this->pasInsertion} ";
140
		$resultat = $this->bdd->recupererTous($requete);
111
		$resultat = $this->getBdd()->recupererTous($requete);
141
		return $resultat;
112
		return $resultat;
142
	}
113
	}
143
 
114
 
144
	private function lancerRequeteModification($nomsSciHtm) {
115
	private function lancerRequeteModification($nomsSciHtm) {
145
		foreach ($nomsSciHtm as $id => $html) {
116
		foreach ($nomsSciHtm as $id => $html) {
146
			$html = $this->bdd->proteger($html);
117
			$html = $this->getBdd()->proteger($html);
147
			$requete = "UPDATE {$this->table} ".
118
			$requete = "UPDATE {$this->table} ".
148
				"SET nom_sci_html = $html ".
119
				"SET nom_sci_html = $html ".
149
				"WHERE num_nom = $id ";
120
				"WHERE num_nom = $id ";
150
			$resultat = $this->bdd->requeter($requete);
121
			$resultat = $this->getBdd()->requeter($requete);
Line 151... Line -...
151
			if ($resultat === false) {
-
 
152
				throw new Exception("Erreur d'insertion pour le tuple $id");
-
 
153
			}
-
 
154
		}
-
 
155
	}
-
 
156
 
-
 
157
	private function stopperLaBoucle() {
-
 
158
		$stop = false;
-
 
159
		static $ligneActuelle = 1;
-
 
160
		if ($nbreLignesATester = $this->getParametre('t')) {
122
			if ($resultat === false) {
161
			if ($nbreLignesATester == $ligneActuelle++) {
123
				throw new Exception("Erreur d'insertion pour le tuple $id");
162
				$stop = true;
124
			}
163
			}
125
		}