Subversion Repositories eFlore/Projets.eflore-projets

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1192 delphine 1
<?php
2
/** Exemple lancement:
3
 * /opt/lampp/bin/php -d memory_limit=3500M cli.php vigie_flore -a chargerTous
4
*/
5
class VigieFlore extends EfloreScript {
6
 
7
	public function executer() {
8
		// Lancement de l'action demandée
9
		try {
10
			$this->initialiserProjet('vigie_flore');
11
 
12
			$cmd = $this->getParametre('a');
13
			switch ($cmd) {
14
				case 'chargerTous' :
15
					$this->chargerStructureSql();
16
					$this->chargerDonnees();
17
					$this->genererVue();
18
					$this->ajouterOntologie();
19
					break;
20
				case 'chargerStructureSql' :
21
					$this->chargerStructureSql();
22
					break;
23
				case 'chargerDonnees' :
24
					$this->chargerDonnees();
25
					$this->genererVue();
26
					$this->ajouterOntologie();
27
					break;
28
				case 'genererVue' :
29
					$this->genererVue();
30
					break;
31
				case 'ajouterOntologie' :
32
					$this->ajouterOntologie();
33
					break;
34
				case 'supprimerTous' :
35
					$this->supprimerTous();
36
					break;
37
				default :
38
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
39
			}
40
		} catch (Exception $e) {
41
			$this->traiterErreur($e->getMessage());
42
		}
43
	}
44
 
45
	protected function chargerDonnees() {
46
		$chemin = Config::get('chemins.donnees');
47
		$table = Config::get('tables.donnees');
48
		$requete = "LOAD DATA INFILE '$chemin' ".
49
			"REPLACE INTO TABLE $table ".
50
			'CHARACTER SET utf8 '.
51
			'FIELDS '.
52
			"	TERMINATED BY '\t' ".
53
			"	ENCLOSED BY '' ".
54
			"	ESCAPED BY '\\\' ".
55
			'IGNORE 1 LINES';
56
		$this->getBdd()->requeter($requete);
57
	}
58
 
59
	private function genererVue() {
60
		$referentielTaxo = Config::get('tables.referentielTaxo');
61
		$donnees = Config::get('tables.donnees');
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,
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
66
				 FROM $referentielTaxo b, $donnees v
67
				 WHERE b.cd_nom = v.num_tax_tax_ref
68
					AND b.num_nom = b.num_nom_retenu;";
69
		$this->getBdd()->requeter($requete);
70
	}
71
 
72
 
73
	private function ajouterOntologie() {
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');";
76
		$this->getBdd()->requeter($requete);
77
	}
78
 
79
	private function supprimerTous() {
80
		$requete = "DROP TABLE IF EXISTS vigie_flore_v2015_03; DROP TABLE vigie_flore_tapir;";
81
		$this->getBdd()->requeter($requete);
82
		Debug::printr('suppression');
83
	}
84
}
85
?>