Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
/** Exemple lancement:
* /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php moissonnage -a chargerDonnees -n baznat
* Options :
* -n : nom du projet
*/
class Moissonnage extends EfloreScript {
private $projet = "";
protected $parametres_autorises = array(
'-n' => array(true, true, 'Préciser le nom du dataset que vous souhaitez ajouter ex. baznat, naturedugard-flore'));
public function executer() {
// Lancement de l'action demandée
try {
$this->initialiserProjet('moissonnage');
$cmd = $this->getParametre('a');
$this->projet = $this->getParametre('n');
switch ($cmd) {
case 'chargerTous' :
$this->chargerDonnees();
$this->chargerMetaDonnees();
break;
case 'chargerDonnees' :
$this->chargerDonnees();
break;
case 'chargerMetadonnees' :
$this->chargerMetaDonnees();
break;
case 'supprimerTous' :
$this->supprimerTous();
break;
default :
throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
}
} catch (Exception $e) {
$this->traiterErreur($e->getMessage());
}
}
private function chargerDonnees() {
$requete = "CREATE TABLE tb_eflore.".$this->projet."_tapir2 ".
"AS SELECT concat('urn:lsid:',institutionCode,':',collectionCode,':', catalogNumber) AS guid, ".
"`catalogNumber` AS observation_id, `scientificName` AS nom_scientifique_complet, `referencess` AS num_nom, ".
"`county` AS lieu_station_nom, `locality` AS lieu_commune_code_insee, ".
"`decimalLatitude` AS lieu_station_latitude, `decimalLongitude` AS lieu_station_longitude, `geodeticDatum` , ".
"`eventDate` AS observation_date, `identifiedBy` AS observateur_nom_complet ".
"FROM tb_moissonnage.Occurrence ".
"WHERE dataset_id = (SELECT dataset_id FROM tb_moissonnage.Dataset WHERE name = '$this->projet')";
$this->getBdd()->requeter($requete);
}
private function chercherInfosMetaDonnees() {
$infos = array();
$requeteOccurrence = "SELECT institutionCode, collectionCode FROM tb_moissonnage.Occurrence WHERE dataset_id =
(SELECT id FROM tb_moissonnage.Dataset WHERE name='$this->projet');";
$infos['occurrence'] = $this->getBdd()->recuperer($requeteOccurrence);
$requeteDataset = "SELECT * FROM tb_moissonnage.DataPublisher WHERE id =
(SELECT dataPublisher_id FROM tb_moissonnage.Dataset WHERE name='$this->projet')";
$infos['dataPublisher'] = $this->getBdd()->recuperer($requeteDataset);
return $infos;
}
private function chargerMetaDonnees() {
$this->chargerStructureSqlMetaDonnees();
$infos = $this->chercherInfosMetaDonnees();
$date = date('Y_m_d');
$requete = "INSERT INTO tb_eflore.".$this->projet."_tapir_meta (guid, citation, url_projet, createurs) ".
"VALUES ('urn:lsid:{$infos['occurrence']['institutionCode']}:{$infos['occurrence']['collectionCode']}:{$date}', '".
$this->projet." : {$infos['dataPublisher']['description']} du ".
"<a href=\"{$infos['occurrence']['institutionCode']}\" title=\"{$infos['occurrence']['collectionCode']}\" ".
"onclick=\"window.open(this.href); return false;\">{$this->projet}</a>', ".
"'{$infos['occurrence']['institutionCode']}', ".
"'p.courriel={$infos['dataPublisher']['administrativeContact']}, p.courriel={$infos['dataPublisher']['technicalContact']}')";
$this->getBdd()->requeter($requete);
}
private function chargerStructureSqlMetaDonnees() {
$date = date('Y_m_d');
$requete = "CREATE TABLE IF NOT EXISTS tb_eflore.".$this->projet."_tapir_meta ".
"(`guid` varchar(255) NOT NULL ,
`langue_meta` varchar(2) NOT NULL DEFAULT 'fr',
`code` varchar(20) NOT NULL DEFAULT '{$this->projet}',
`version` varchar(20) NOT NULL DEFAULT '{$date}',
`titre` varchar(255) NOT NULL DEFAULT '{$this->projet}',
`description` text,
`mots_cles` varchar(510) NOT NULL DEFAULT 'flore, observation, {$this->projet}',
`citation` varchar(255) NOT NULL,
`url_tech` varchar(510) DEFAULT NULL,
`url_projet` varchar(510) NOT NULL,
`source` text,
`createurs` text NOT NULL,
`editeur` text,
`contributeurs` text,
`droits` text,
`url_droits` varchar(510) DEFAULT 'http://creativecommons.org/licenses/by-sa/2.0/fr/',
`langue` varchar(255) DEFAULT 'fr',
`date_creation` varchar(30) DEFAULT NULL,
`date_validite` varchar(255) DEFAULT NULL,
`couverture_spatiale` varchar(510) DEFAULT NULL,
`couverture_temporelle` varchar(510) DEFAULT NULL,
`web_services` varchar(255) DEFAULT 'meta-donnees:0.1;ontologies:0.1;cartes:0.1',
PRIMARY KEY (`guid`,`langue_meta`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
$this->getBdd()->requeter($requete);
}
private function supprimerTous() {
$requete = "DROP TABLE IF EXISTS `ifn_arbres_forets`, `ifn_arbres_peupleraie`, `ifn_couverts_foret`,
`ifn_documentation`, `ifn_documentation_flore`, `ifn_ecologie`, `ifn_flore`, `ifn_placettes_foret`,
`ifn_placettes_peupleraie`;
";
$this->getBdd()->requeter($requete);
}
}
?>