Rev 42 | Rev 130 | 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 insee_d
* -a chargerTous
* Options :
* -t : Permet de tester le script sur un jeux réduit de données (indiquer le nombre de lignes).
*/
class InseeD extends Script {
private $bdd = null;
private $projetNom = 'insee-d';
public function executer() {
// Lancement de l'action demandée
try {
$this->chargerConfigDuProjet();
$this->bdd = new Bdd();
$cmd = $this->getParametre('a');
switch ($cmd) {
case 'chargerTous' :
$this->chargerStructureSql();
$this->chargerInseeD();
$this->chargerOntologies();
break;
case 'chargerStructureSql' :
$this->chargerStructureSql();
break;
case 'chargerInseeD' :
$this->chargerInseeD();
break;
case 'chargerOntologies' :
$this->chargerOntologies();
break;
default :
$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
}
} catch (Exception $e) {
$this->traiterErreur($e->getMessage());
}
}
private function chargerConfigDuProjet() {
$fichierIni = dirname(__FILE__).DS.$this->projetNom.'.ini';
if (file_exists($fichierIni)) {
Config::charger($fichierIni);
} else {
$m = "Veuillez configurer le projet en créant le fichier '{$this->projetNom}.ini' ".
"dans le dossier du module de script du projet à partir du fichier '{$this->projetNom}.defaut.ini'.";
throw new Exception($m);
}
}
private function chargerStructureSql() {
$chemin = Config::get('chemins.structureSql');
$requetes = Outils::extraireRequetes($chemin);
foreach ($requetes as $requete) {
$this->bdd->requeter($requete);
}
}
private function chargerInseeD() {
$chemin = Config::get('chemins.inseeD');
$table = Config::get('tables.inseeD');
$requete = "LOAD DATA INFILE '$chemin' ".
"REPLACE INTO TABLE $table ".
'CHARACTER SET utf8 '.
'FIELDS '.
" TERMINATED BY ';' ".
" ENCLOSED BY '\"' ".
" ESCAPED BY '\\\' ".
'IGNORE 0 LINES';
$this->bdd->requeter($requete);
}
private function chargerOntologies() {
$chemin = Config::get('chemins.ontologies');
$table = Config::get('tables.ontologies');
$requete = "LOAD DATA INFILE '$chemin' ".
"REPLACE INTO TABLE $table ".
'CHARACTER SET utf8 '.
'FIELDS '.
" TERMINATED BY '\t' ".
" ENCLOSED BY '' ".
" ESCAPED BY '\\\' ".
'IGNORE 1 LINES';
$this->bdd->requeter($requete);
}
}
?>