Subversion Repositories Applications.referentiel

Rev

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

Rev 380 Rev 382
Line 47... Line 47...
47
		// Bibliothèque Algolia PHP pour appeler l'API
47
		// Bibliothèque Algolia PHP pour appeler l'API
48
		Config::charger(dirname(__FILE__) . '/algolia.ini');
48
		Config::charger(dirname(__FILE__) . '/algolia.ini');
49
		$this->algolia = new \AlgoliaSearch\Client(Config::get('algolia_application_id'), Config::get('algolia_api_key'));
49
		$this->algolia = new \AlgoliaSearch\Client(Config::get('algolia_application_id'), Config::get('algolia_api_key'));
50
		$this->indexAlgolia = $this->algolia->initIndex(Config::get('algolia_index'));
50
		$this->indexAlgolia = $this->algolia->initIndex(Config::get('algolia_index'));
Line -... Line 51...
-
 
51
 
-
 
52
		/*$settings = $this->indexAlgolia->getSettings();
-
 
53
		var_dump(json_encode($settings));
-
 
54
		exit;*/
-
 
55
 
-
 
56
		// Réglages de l'index @TODO tenir à jour
-
 
57
		if ($this->confirmer("Charger les réglages par défaut (index_settings.json) dans la configuration de l'index Algolia ?")) {
-
 
58
			// Chargement des réglages par défaut
-
 
59
			$reglagesJson = file_get_contents(dirname(__FILE__) . '/index_settings.json');
-
 
60
			$reglages = json_decode($reglagesJson, true);
-
 
61
			$this->indexAlgolia->setSettings($reglages);
-
 
62
			echo "Réglages chargés dans Algolia" . PHP_EOL;
-
 
63
		}
51
 
64
 
52
		// Connexion à la base
65
		// Connexion à la base
Line 53... Line 66...
53
		$this->connecterPDO();
66
		$this->connecterPDO();
54
 
67
 
Line 89... Line 102...
89
			echo "Aucun référentiel à mettre à jour" . PHP_EOL;
102
			echo "Aucun référentiel à mettre à jour" . PHP_EOL;
90
			exit;
103
			exit;
91
		}
104
		}
Line 92... Line 105...
92
 
105
 
93
		// Confirmation
106
		// Confirmation
-
 
107
		if (! $this->confirmer("Fusion des référentiels [" . implode(',', $refs) . "] et mise à jour de [" . implode(',', $refsMaj) . "]. Continuer ?")) {
-
 
108
			exit;
Line 94... Line 109...
94
		//$this->confirmer("Fusion des référentiels [" . implode(',', $refs) . "] et mise à jour de [" . implode(',', $refsMaj) . "]. Continuer ?");
109
		}
95
 
110
 
96
		//var_dump($refs);
111
		//var_dump($refs);
97
		$donneesBrutes = array();
112
		$donneesBrutes = array();
Line 117... Line 132...
117
		$index = $this->fusionnerReferentiels($donneesBrutes);
132
		$index = $this->fusionnerReferentiels($donneesBrutes);
118
		//$this->extrait($index, array('Acacia dealbata Link','Acacia Mill.','Fabaceae'));
133
		//$this->extrait($index, array('Acacia dealbata Link','Acacia Mill.','Fabaceae'));
Line 119... Line 134...
119
 
134
 
120
		// Mise en forme
135
		// Mise en forme
121
		$index = $this->mettreEnForme($index);
136
		$index = $this->mettreEnForme($index);
Line 122... Line 137...
122
		$this->extrait($index, 3);
137
		//$this->extrait($index, 3);
123
 
138
 
124
		// Stats
139
		// Stats
125
		$taille = count($index);
140
		$taille = count($index);
Line 213... Line 228...
213
				$cultivar_groupe = $taxon[$ref . '_cultivar_groupe'];
228
				$cultivar_groupe = $taxon[$ref . '_cultivar_groupe'];
214
				$nomCommun = (isset($taxon[$ref . '_nom_francais']) ? $taxon[$ref . '_nom_francais'] : '');
229
				$nomCommun = (isset($taxon[$ref . '_nom_francais']) ? $taxon[$ref . '_nom_francais'] : '');
215
				$url = $taxon[$ref . '_url'];
230
				$url = $taxon[$ref . '_url'];
216
				$synonymes = json_decode($taxon[$ref . '_synonymes'], true);
231
				$synonymes = json_decode($taxon[$ref . '_synonymes'], true);
217
				$raccourcis = json_decode($taxon[$ref . '_shortcuts'], true);
232
				$raccourcis = json_decode($taxon[$ref . '_shortcuts'], true);
218
				$raccourcis = array_values(array_unique($raccourcis)); // array_values réindexe pour obtenir une liste en JSON et non un objet
233
				$raccourcis = ($raccourcis != null ? array_values(array_unique($raccourcis)) : null); // array_values réindexe pour obtenir une liste en JSON et non un objet
219
				// garniture
234
				// garniture
220
				$donneesRef = array(
235
				$donneesRef = array(
221
					'nomenclatural_number' => intval($nn),
236
					'nomenclatural_number' => intval($nn),
222
					'scientific_name' => $ns,
237
					'scientific_name' => $ns,
223
					'common_name' => $nomCommun,
238
					'common_name' => $nomCommun,
Line 243... Line 258...
243
		}
258
		}
244
		return $nouvelIndex;
259
		return $nouvelIndex;
245
	}
260
	}
Line 246... Line 261...
246
 
261
 
-
 
262
	protected function insererDansAlgolia($index) {
247
	protected function insererDansAlgolia($index) {
263
		$tailleTranche = 30000;
248
		echo "++++ Insertion dans Algolia !! ++++" . PHP_EOL;
264
		echo "++++ Insertion dans Algolia ($tailleTranche) !! ++++" . PHP_EOL;
249
		$tranche = array_slice($index, 0, 500);
265
		$tranche = array_slice($index, 0, $tailleTranche);
250
		//var_dump($tranche);
266
		//var_dump($tranche);
251
		//$trancheJSON = json_encode($tranche);
267
		//$trancheJSON = json_encode($tranche);
252
		$this->indexAlgolia->addObjects($tranche);
268
		$this->indexAlgolia->addObjects($tranche);
253
		//$this->algolia->
269
		//$this->algolia->
Line 307... Line 323...
307
		echo $question . ' ("' . $codeAcceptation . '" pour confirmer, autre chose pour annuler)' . PHP_EOL;
323
		echo $question . ' ("' . $codeAcceptation . '" pour confirmer, autre chose pour annuler)' . PHP_EOL;
308
		$handle = fopen ("php://stdin","r");
324
		$handle = fopen ("php://stdin","r");
309
		$line = fgets($handle);
325
		$line = fgets($handle);
310
		if(strtolower(trim($line)) != strtolower($codeAcceptation)) {
326
		if(strtolower(trim($line)) != strtolower($codeAcceptation)) {
311
			echo $messageAnnulation . PHP_EOL;
327
			echo $messageAnnulation . PHP_EOL;
312
			exit;
328
			return false;
313
		}
329
		}
314
		fclose($handle);
330
		fclose($handle);
-
 
331
		return true;
315
	}
332
	}
316
}
333
}
317
?>
334
?>
318
335