Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 339 Rev 340
Line 30... Line 30...
30
			$cmd = $this->getParametre('a');
30
			$cmd = $this->getParametre('a');
31
			switch ($cmd) {
31
			switch ($cmd) {
32
				case 'chargerTous' :
32
				case 'chargerTous' :
33
					$this->chargerStructureSql();
33
					$this->chargerStructureSql();
34
					$this->chargerBdtfx();
34
					$this->chargerBdtfx();
35
					$this->genererNomSciHtml();
35
					$this->genererChpNomSciHtml();
-
 
36
					$this->genererChpFamille();
36
					$this->genererDonneesTestMultiVersion();
37
					$this->genererDonneesTestMultiVersion();
37
					break;
38
					break;
38
				case 'chargerStructureSql' :
39
				case 'chargerStructureSql' :
39
					$this->chargerStructureSql();
40
					$this->chargerStructureSql();
40
					break;
41
					break;
41
				case 'chargerBdtfx' :
42
				case 'chargerBdtfx' :
42
					$this->chargerBdtfx();
43
					$this->chargerBdtfx();
43
					break;
44
					break;
44
				case 'genererNomSciHtml' :
45
				case 'genererNomSciHtml' :
45
					$this->genererNomSciHtml();
46
					$this->genererChpNomSciHtml();
46
					break;
47
					break;
47
				case 'genererChpFamille' :
48
				case 'genererChpFamille' :
48
					$this->genererChpFamille();
49
					$this->genererChpFamille();
49
					break;
50
					break;
50
				case 'genererDonneesTestMultiVersion' :
51
				case 'genererDonneesTestMultiVersion' :
Line 76... Line 77...
76
				"	ESCAPED BY '\\\' ".
77
				"	ESCAPED BY '\\\' ".
77
				'IGNORE 1 LINES';
78
				'IGNORE 1 LINES';
78
		$this->getBdd()->requeter($requete);
79
		$this->getBdd()->requeter($requete);
79
	}
80
	}
Line 80... Line 81...
80
 
81
 
81
	private function genererNomSciHtml() {
82
	private function genererChpNomSciHtml() {
82
		$this->initialiserGenerationChamps();
83
		$this->initialiserGenerationChamps();
83
		$this->preparerTablePrChpNomSciHtml();
84
		$this->preparerTablePrChpNomSciHtml();
84
		$generateur = new GenerateurNomSciHtml();
85
		$generateur = new GenerateurNomSciHtml();
85
		$nbreTotal = $this->recupererNbTotalTuples();
86
		$nbreTotal = $this->recupererNbTotalTuples();
86
		$this->departInsertion = 0;
87
		$this->departInsertion = 0;
87
		while ($this->departInsertion < $nbreTotal) {
88
		while ($this->departInsertion < $nbreTotal) {
88
			$resultat = $this->recupererTuples();
89
			$resultat = $this->recupererTuplesPrChpNomSciHtml();
89
			$nomsSciEnHtml = $generateur->generer($resultat);
90
			$nomsSciEnHtml = $generateur->generer($resultat);
90
			$this->lancerRequeteModification($nomsSciEnHtml);
91
			$this->remplirChpNomSciHtm($nomsSciEnHtml);
91
			$this->departInsertion += $this->pasInsertion;
92
			$this->departInsertion += $this->pasInsertion;
92
			$this->afficherAvancement("Insertion des noms scientifique au format HTML dans la base par paquet de {$this->pasInsertion} en cours");
93
			$this->afficherAvancement("Insertion des noms scientifique au format HTML dans la base par paquet de {$this->pasInsertion} en cours");
93
			if ($this->stopperLaBoucle($this->getParametre('t'))) break;
94
			if ($this->stopperLaBoucle($this->getParametre('t'))) break;
94
		}
95
		}
Line 114... Line 115...
114
		$requete = "SELECT count(*) AS nb FROM {$this->table} ";
115
		$requete = "SELECT count(*) AS nb FROM {$this->table} ";
115
		$resultat = $this->getBdd()->recuperer($requete);
116
		$resultat = $this->getBdd()->recuperer($requete);
116
		return $resultat['nb'];
117
		return $resultat['nb'];
117
	}
118
	}
Line 118... Line 119...
118
 
119
 
119
	private function recupererTuples() {
120
	private function recupererTuplesPrChpNomSciHtml() {
120
		$requete = 'SELECT 	num_nom, rang, nom_supra_generique, genre, epithete_infra_generique, '.
121
		$requete = 'SELECT 	num_nom, rang, nom_supra_generique, genre, epithete_infra_generique, '.
121
			'	epithete_sp, type_epithete, epithete_infra_sp,cultivar_groupe, '.
122
			'	epithete_sp, type_epithete, epithete_infra_sp,cultivar_groupe, '.
122
			'	nom_commercial, cultivar '.
123
			'	nom_commercial, cultivar '.
123
			"FROM {$this->table} ".
124
			"FROM {$this->table} ".
124
			"LIMIT {$this->departInsertion},{$this->pasInsertion} ";
125
			"LIMIT {$this->departInsertion},{$this->pasInsertion} ";
125
		$resultat = $this->getBdd()->recupererTous($requete);
126
		$resultat = $this->getBdd()->recupererTous($requete);
126
		return $resultat;
127
		return $resultat;
Line 127... Line 128...
127
	}
128
	}
128
 
129
 
129
	private function lancerRequeteModification($nomsSciHtm) {
130
	private function remplirChpNomSciHtm($nomsSciHtm) {
130
		foreach ($nomsSciHtm as $id => $html) {
131
		foreach ($nomsSciHtm as $id => $html) {
131
			$html = $this->getBdd()->proteger($html);
-
 
132
			$requete = "UPDATE {$this->table} ".
-
 
133
				"SET nom_sci_html = $html ".
132
			$html = $this->getBdd()->proteger($html);
134
				"WHERE num_nom = $id ";
133
			$requete = "UPDATE {$this->table} SET nom_sci_html = $html WHERE num_nom = $id ";
135
			$resultat = $this->getBdd()->requeter($requete);
134
			$resultat = $this->getBdd()->requeter($requete);
136
			if ($resultat === false) {
135
			if ($resultat === false) {
137
				throw new Exception("Erreur d'insertion pour le tuple $id");
136
				throw new Exception("Erreur d'insertion pour le tuple $id");
Line 141... Line 140...
141
 
140
 
142
	private function genererChpFamille() {
141
	private function genererChpFamille() {
143
		$this->initialiserGenerationChamps();
142
		$this->initialiserGenerationChamps();
144
		$this->preparerTablePrChpFamille();
143
		$this->preparerTablePrChpFamille();
145
		$resultats = $this->recupererTuplesPrChpFamille();
-
 
146
		$famille = array();
144
		$resultats = $this->recupererTuplesPrChpFamille();
147
		$noms = array();
145
		$noms = array();
148
		$introuvables = array();
146
		$introuvables = array();
149
		$introuvablesSyno = array();
147
		$introuvablesSyno = array();
150
		foreach ($resultats as $id => $nom) {
148
		foreach ($resultats as $id => $nom) {
151
			$nn = $nom['num_nom'];
149
			$nn = $nom['num_nom'];
152
			$nnr = $nom['num_nom_retenu'];
150
			$nnr = $nom['num_nom_retenu'];
153
			$nts = $nom['num_tax_sup'];
151
			$nts = $nom['num_tax_sup'];
154
			$rg = $nom['rang'];
152
			$rg = $nom['rang'];
155
			if ($nnr != '') {
153
			if ($nnr != '') {
156
				if ($rg == '180') {
154
				if ($rg == '180') {
157
					$famille[$nn] = $nom['nom_sci'];
155
					$noms[$nn] = $nom['nom_sci'];
158
				} else {
156
				} else {
159
					if ($nn == $nnr) {// nom retenu
157
					if ($nn == $nnr) {// nom retenu
160
						if (isset($noms[$nts])) {
158
						if (isset($noms[$nts])) {
161
							$noms[$nn] = $noms[$nts];
-
 
162
						} else if (isset($famille[$nts])) {
-
 
163
							$noms[$nn] = $famille[$nts];
159
							$noms[$nn] = $noms[$nts];
164
						} else {
160
						} else {
165
							$introuvables[] = $nn;
161
							$introuvables[] = $nn;
166
						}
162
						}
167
					} else {// nom synonyme
163
					} else {// nom synonyme
Line 199... Line 195...
199
			$logContenu = implode(", \n", $introuvables);
195
			$logContenu = implode(", \n", $introuvables);
200
			$logFichier = realpath(dirname(__FILE__)).'/log/famille_introuvable.log';
196
			$logFichier = realpath(dirname(__FILE__)).'/log/famille_introuvable.log';
201
			echo $logFichier."\n";
197
			echo $logFichier."\n";
202
			file_put_contents($logFichier, $logContenu);
198
			file_put_contents($logFichier, $logContenu);
203
		}
199
		}
204
		if (count($introuvablesSyno) != 0) {
-
 
205
			//$introuvablesSyno = implode(', ', $introuvablesSyno);
-
 
206
			$introuvablesSyno = count($introuvablesSyno);
-
 
207
			echo "Synonyme avec nom retenu introuvable : $introuvablesSyno\n";
-
 
208
		}
-
 
209
		$this->lancerRequeteModificationPrChpFamille($noms);
200
		$this->remplirChpFamille($noms);
210
	}
201
	}
Line 211... Line 202...
211
 
202
 
212
	private function preparerTablePrChpFamille() {
203
	private function preparerTablePrChpFamille() {
213
		$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'famille' ";
204
		$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'famille' ";
Line 222... Line 213...
222
 
213
 
223
	private function recupererTuplesPrChpFamille() {
214
	private function recupererTuplesPrChpFamille() {
224
		$requete = 'SELECT num_nom, num_nom_retenu, num_tax_sup, rang, nom_sci '.
215
		$requete = 'SELECT num_nom, num_nom_retenu, num_tax_sup, rang, nom_sci '.
225
				"FROM {$this->table} ".
216
				"FROM {$this->table} ".
226
				"WHERE rang >= 180 ".
217
				"WHERE rang >= 180 ".
227
				"ORDER BY rang ASC, num_tax_sup ASC , num_nom_retenu DESC ";
-
 
228
		//echo $requete."\n";
218
				"ORDER BY rang ASC, num_tax_sup ASC, num_nom_retenu DESC ";
229
		$resultat = $this->getBdd()->recupererTous($requete);
219
		$resultat = $this->getBdd()->recupererTous($requete);
230
		return $resultat;
220
		return $resultat;
Line 231... Line 221...
231
	}
221
	}
232
 
222
 
233
	private function lancerRequeteModificationPrChpFamille($noms) {
223
	private function remplirChpFamille($noms) {
234
		foreach ($noms as $id => $famille) {
224
		foreach ($noms as $id => $famille) {
235
			$famille = $this->getBdd()->proteger($famille);
-
 
236
			$requete = "UPDATE {$this->table} ".
-
 
237
					"SET famille = $famille ".
225
			$famille = $this->getBdd()->proteger($famille);
238
					"WHERE num_nom = $id ";
226
			$requete = "UPDATE {$this->table} SET famille = $famille WHERE num_nom = $id ";
239
			$resultat = $this->getBdd()->requeter($requete);
227
			$resultat = $this->getBdd()->requeter($requete);
240
			if ($resultat === false) {
228
			if ($resultat === false) {
241
				throw new Exception("Erreur d'insertion pour le tuple $id");
229
				throw new Exception("Erreur d'insertion pour le tuple $id");