Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1192 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1192 Rev 1202
1
<?php
1
<?php
2
/** Exemple lancement:
2
/** Exemple lancement:
3
 * /opt/lampp/bin/php -d memory_limit=3500M cli.php vigie_flore -a chargerTous
3
 * /opt/lampp/bin/php -d memory_limit=3500M cli.php vigie_flore -a chargerTous
4
*/
4
*/
5
class VigieFlore extends EfloreScript {
5
class VigieFlore extends EfloreScript {
6
 
6
 
7
	public function executer() {
7
	public function executer() {
8
		// Lancement de l'action demandée
8
		// Lancement de l'action demandée
9
		try {
9
		try {
10
			$this->initialiserProjet('vigie_flore');
10
			$this->initialiserProjet('vigie_flore');
11
 
11
 
12
			$cmd = $this->getParametre('a');
12
			$cmd = $this->getParametre('a');
13
			switch ($cmd) {
13
			switch ($cmd) {
14
				case 'chargerTous' :
14
				case 'chargerTous' :
15
					$this->chargerStructureSql();
15
					$this->chargerStructureSql();
16
					$this->chargerDonnees();
16
					$this->chargerDonnees();
17
					$this->genererVue();
17
					$this->genererVue();
18
					$this->ajouterOntologie();
18
					$this->ajouterOntologie();
19
					break;
19
					break;
20
				case 'chargerStructureSql' :
20
				case 'chargerStructureSql' :
21
					$this->chargerStructureSql();
21
					$this->chargerStructureSql();
22
					break;
22
					break;
23
				case 'chargerDonnees' :
23
				case 'chargerDonnees' :
24
					$this->chargerDonnees();
24
					$this->chargerDonnees();
25
					$this->genererVue();
25
					$this->genererVue();
26
					$this->ajouterOntologie();
26
					$this->ajouterOntologie();
27
					break;
27
					break;
28
				case 'genererVue' :
28
				case 'genererVue' :
29
					$this->genererVue();
29
					$this->genererVue();
30
					break;
30
					break;
31
				case 'ajouterOntologie' :
31
				case 'ajouterOntologie' :
32
					$this->ajouterOntologie();
32
					$this->ajouterOntologie();
33
					break;
33
					break;
34
				case 'supprimerTous' :
34
				case 'supprimerTous' :
35
					$this->supprimerTous();
35
					$this->supprimerTous();
36
					break;
36
					break;
37
				default :
37
				default :
38
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
38
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
39
			}
39
			}
40
		} catch (Exception $e) {
40
		} catch (Exception $e) {
41
			$this->traiterErreur($e->getMessage());
41
			$this->traiterErreur($e->getMessage());
42
		}
42
		}
43
	}
43
	}
44
 
44
 
45
	protected function chargerDonnees() {
45
	protected function chargerDonnees() {
46
		$chemin = Config::get('chemins.donnees');
46
		$chemin = Config::get('chemins.donnees');
47
		$table = Config::get('tables.donnees');
47
		$table = Config::get('tables.donnees');
48
		$requete = "LOAD DATA INFILE '$chemin' ".
48
		$requete = "LOAD DATA INFILE '$chemin' ".
49
			"REPLACE INTO TABLE $table ".
49
			"REPLACE INTO TABLE $table ".
50
			'CHARACTER SET utf8 '.
50
			'CHARACTER SET utf8 '.
51
			'FIELDS '.
51
			'FIELDS '.
52
			"	TERMINATED BY '\t' ".
52
			"	TERMINATED BY '\t' ".
53
			"	ENCLOSED BY '' ".
53
			"	ENCLOSED BY '' ".
54
			"	ESCAPED BY '\\\' ".
54
			"	ESCAPED BY '\\\' ".
55
			'IGNORE 1 LINES';
55
			'IGNORE 1 LINES';
56
		$this->getBdd()->requeter($requete);
56
		$this->getBdd()->requeter($requete);
57
	}
57
	}
58
	
58
	
59
	private function genererVue() {
59
	private function genererVue() {
60
		$referentielTaxo = Config::get('tables.referentielTaxo');
60
		$referentielTaxo = Config::get('tables.referentielTaxo');
61
		$donnees = Config::get('tables.donnees');
61
		$donnees = Config::get('tables.donnees');
62
		$requete = "CREATE VIEW vigie_flore_tapir AS 
62
		$requete = "CREATE VIEW vigie_flore_tapir AS 
63
			SELECT '' as observation_id, b.nom_sci as nom_scientifique_complet, v.nom_sci as nom_sci, b.num_nom, 
63
			SELECT '' as observation_id, b.nom_sci as nom_scientifique_complet, v.nom_sci as nom_sci, b.num_nom, 
64
				 v.commune as lieu_commune_code_insee, v.latitude as lieu_station_latitude, v.longitude as lieu_station_longitude,
64
				 v.commune as lieu_commune_code_insee, v.latitude as lieu_station_latitude, v.longitude as lieu_station_longitude,
65
				 ref_geo AS geodeticDatum, v.date as observation_date, observateur AS observateur_nom_complet
65
				 ref_geo AS geodeticDatum, v.date as observation_date, observateur AS observateur_nom_complet
66
				 FROM $referentielTaxo b, $donnees v
66
				 FROM $referentielTaxo b, $donnees v
67
				 WHERE b.cd_nom = v.num_tax_tax_ref
67
				 WHERE b.cd_nom = v.num_tax_tax_ref
68
					AND b.num_nom = b.num_nom_retenu;";
68
					AND b.num_nom = b.num_nom_retenu;";
69
		$this->getBdd()->requeter($requete);
69
		$this->getBdd()->requeter($requete);
70
	}
70
	}
71
	
71
	
72
 
72
 
73
	private function ajouterOntologie() {
73
	private function ajouterOntologie() {
74
		$requete = "INSERT INTO `eflore_ontologies` (`id`, `classe_id`, `nom`, `description`, `code`, `complements`) VALUES
74
		$requete = "INSERT INTO `eflore_ontologies` (`id`, `classe_id`, `nom`, `description`, `code`, `complements`) VALUES
75
				(25, 10, 'Vigie Flore', 'données issues du <a href=\"http://vigienature.mnhn.fr/flore/vigie-flore\" title=\"Vigie-Flore\" onclick=\"window.open(this.href); return false;\">programme Vigie-Flore</a>', 'VF', 'legende=#9527BA');";
75
				(25, 10, 'Vigie Flore', 'données issues du <a href=\"http://vigienature.mnhn.fr/flore/vigie-flore\" title=\"Vigie-Flore\" onclick=\"window.open(this.href); return false;\">programme Vigie-Flore</a>', 'VF', 'legende=#BD00FF');";
76
		$this->getBdd()->requeter($requete);
76
		$this->getBdd()->requeter($requete);
77
	}
77
	}
78
	
78
	
79
	private function supprimerTous() {
79
	private function supprimerTous() {
80
		$requete = "DROP TABLE IF EXISTS vigie_flore_v2015_03; DROP TABLE vigie_flore_tapir;";
80
		$requete = "DROP TABLE IF EXISTS vigie_flore_v2015_03; DROP TABLE vigie_flore_tapir;";
81
		$this->getBdd()->requeter($requete);
81
		$this->getBdd()->requeter($requete);
82
		Debug::printr('suppression');
82
		Debug::printr('suppression');
83
	}
83
	}
84
}
84
}
85
?>
85
?>