Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1005 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1000 delphine 1
<?php
2
/** Exemple lancement:
1005 mathias 3
 * /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php moissonnage -a chargerTous -n baznat
1000 delphine 4
 * Options :
5
 * -n : nom du projet
6
*/
7
 
8
class Moissonnage extends EfloreScript {
9
	private $projet = "";
10
	protected $parametres_autorises = array(
11
		'-n' => array(true, true, 'Préciser le nom du dataset que vous souhaitez ajouter ex. baznat, naturedugard-flore'));
12
 
13
	public function executer() {
14
		// Lancement de l'action demandée
15
		try {
16
			$this->initialiserProjet('moissonnage');
17
 
18
			$cmd = $this->getParametre('a');
19
			$this->projet = $this->getParametre('n');
20
			switch ($cmd) {
21
				case 'chargerTous' :
22
					$this->chargerDonnees();
23
					$this->chargerMetaDonnees();
24
					break;
25
				case 'chargerDonnees' :
26
					$this->chargerDonnees();
27
					break;
28
				case 'chargerMetadonnees' :
29
					$this->chargerMetaDonnees();
30
					break;
31
				case 'supprimerTous' :
32
					$this->supprimerTous();
33
					break;
34
				default :
35
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
36
			}
37
		} catch (Exception $e) {
38
			$this->traiterErreur($e->getMessage());
39
		}
40
	}
41
 
42
	private function chargerDonnees() {
43
		$requete = "CREATE TABLE tb_eflore.".$this->projet."_tapir2 ".
44
					"AS SELECT concat('urn:lsid:',institutionCode,':',collectionCode,':', catalogNumber) AS guid, ".
45
						"`catalogNumber` AS observation_id, `scientificName` AS nom_scientifique_complet, `referencess` AS num_nom, ".
46
						"`county` AS lieu_station_nom, `locality` AS lieu_commune_code_insee, ".
47
						"`decimalLatitude` AS lieu_station_latitude, `decimalLongitude` AS lieu_station_longitude, `geodeticDatum` , ".
48
						"`eventDate` AS observation_date,  `identifiedBy` AS observateur_nom_complet ".
49
					"FROM tb_moissonnage.Occurrence ".
50
					"WHERE dataset_id = (SELECT dataset_id FROM tb_moissonnage.Dataset WHERE name = '$this->projet')";
51
		$this->getBdd()->requeter($requete);
52
	}
53
 
54
	private function chercherInfosMetaDonnees() {
55
		$infos = array();
56
		$requeteOccurrence = "SELECT institutionCode, collectionCode FROM tb_moissonnage.Occurrence WHERE dataset_id =
57
			(SELECT id FROM tb_moissonnage.Dataset WHERE name='$this->projet');";
58
		$infos['occurrence'] = $this->getBdd()->recuperer($requeteOccurrence);
59
		$requeteDataset = "SELECT * FROM  tb_moissonnage.DataPublisher WHERE id =
60
			(SELECT dataPublisher_id FROM tb_moissonnage.Dataset WHERE name='$this->projet')";
61
		$infos['dataPublisher'] = $this->getBdd()->recuperer($requeteDataset);
62
		return $infos;
63
	}
64
 
65
 
66
	private function chargerMetaDonnees() {
67
		$this->chargerStructureSqlMetaDonnees();
68
		$infos = $this->chercherInfosMetaDonnees();
69
		$date = date('Y_m_d');
70
		$requete = "INSERT INTO tb_eflore.".$this->projet."_tapir_meta (guid, citation, url_projet, createurs) ".
71
			"VALUES ('urn:lsid:{$infos['occurrence']['institutionCode']}:{$infos['occurrence']['collectionCode']}:{$date}', '".
72
			$this->projet." : {$infos['dataPublisher']['description']} du ".
73
			"<a href=\"{$infos['occurrence']['institutionCode']}\" title=\"{$infos['occurrence']['collectionCode']}\" ".
74
			"onclick=\"window.open(this.href); return false;\">{$this->projet}</a>', ".
75
			"'{$infos['occurrence']['institutionCode']}', ".
76
			"'p.courriel={$infos['dataPublisher']['administrativeContact']}, p.courriel={$infos['dataPublisher']['technicalContact']}')";
77
		$this->getBdd()->requeter($requete);
78
	}
79
 
80
	private function chargerStructureSqlMetaDonnees() {
81
		$date = date('Y_m_d');
82
		$requete = "CREATE TABLE IF NOT EXISTS tb_eflore.".$this->projet."_tapir_meta ".
83
								 "(`guid` varchar(255) NOT NULL ,
84
								  `langue_meta` varchar(2) NOT NULL DEFAULT 'fr',
85
								  `code` varchar(20) NOT NULL DEFAULT '{$this->projet}',
86
								  `version` varchar(20) NOT NULL DEFAULT '{$date}',
87
								  `titre` varchar(255) NOT NULL DEFAULT '{$this->projet}',
88
								  `description` text,
89
								  `mots_cles` varchar(510) NOT NULL DEFAULT 'flore, observation, {$this->projet}',
90
								  `citation` varchar(255) NOT NULL,
91
 
92
								  `url_tech` varchar(510) DEFAULT NULL,
93
								  `url_projet` varchar(510) NOT NULL,
94
								  `source` text,
95
								  `createurs` text NOT NULL,
96
								  `editeur` text,
97
								  `contributeurs` text,
98
								  `droits` text,
99
								  `url_droits` varchar(510) DEFAULT 'http://creativecommons.org/licenses/by-sa/2.0/fr/',
100
								  `langue` varchar(255) DEFAULT 'fr',
101
								  `date_creation` varchar(30) DEFAULT NULL,
102
								  `date_validite` varchar(255) DEFAULT NULL,
103
								  `couverture_spatiale` varchar(510) DEFAULT NULL,
104
								  `couverture_temporelle` varchar(510) DEFAULT NULL,
105
								  `web_services` varchar(255) DEFAULT 'meta-donnees:0.1;ontologies:0.1;cartes:0.1',
106
								  PRIMARY KEY (`guid`,`langue_meta`)
107
								) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
108
		$this->getBdd()->requeter($requete);
109
	}
110
 
111
 
112
	private function supprimerTous() {
113
		$requete = "DROP TABLE IF EXISTS `ifn_arbres_forets`, `ifn_arbres_peupleraie`, `ifn_couverts_foret`,
114
			 `ifn_documentation`, `ifn_documentation_flore`, `ifn_ecologie`, `ifn_flore`, `ifn_placettes_foret`,
115
			 `ifn_placettes_peupleraie`;
116
		";
117
		$this->getBdd()->requeter($requete);
118
	}
119
}
120
?>