33 |
jpm |
1 |
<?php
|
|
|
2 |
/** Exemple lancement:
|
42 |
jpm |
3 |
* /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php insee_d
|
33 |
jpm |
4 |
* -a chargerTous
|
|
|
5 |
* Options :
|
|
|
6 |
* -t : Permet de tester le script sur un jeux réduit de données (indiquer le nombre de lignes).
|
|
|
7 |
*/
|
|
|
8 |
class InseeD extends Script {
|
|
|
9 |
|
|
|
10 |
private $bdd = null;
|
|
|
11 |
private $projetNom = 'insee-d';
|
|
|
12 |
|
|
|
13 |
protected $parametres_autorises = array(
|
|
|
14 |
'-t' => array(false, true, 'Permet de tester le script sur un jeux réduit de données (indiquer le nombre de lignes).'));
|
|
|
15 |
|
|
|
16 |
public function executer() {
|
|
|
17 |
// Lancement de l'action demandée
|
|
|
18 |
try {
|
|
|
19 |
$this->chargerConfigDuProjet();
|
|
|
20 |
$this->bdd = new Bdd();
|
|
|
21 |
|
|
|
22 |
$cmd = $this->getParametre('a');
|
|
|
23 |
switch ($cmd) {
|
|
|
24 |
case 'chargerTous' :
|
|
|
25 |
$this->chargerStructureSql();
|
|
|
26 |
$this->chargerInseeD();
|
|
|
27 |
$this->chargerOntologies();
|
|
|
28 |
break;
|
|
|
29 |
case 'chargerStructureSql' :
|
|
|
30 |
$this->chargerStructureSql();
|
|
|
31 |
break;
|
|
|
32 |
case 'chargerInseeD' :
|
|
|
33 |
$this->chargerInseeD();
|
|
|
34 |
break;
|
|
|
35 |
case 'chargerOntologies' :
|
|
|
36 |
$this->chargerOntologies();
|
|
|
37 |
break;
|
|
|
38 |
default :
|
|
|
39 |
$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
|
|
|
40 |
}
|
|
|
41 |
} catch (Exception $e) {
|
|
|
42 |
$this->traiterErreur($e->getMessage());
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
private function chargerConfigDuProjet() {
|
|
|
47 |
$fichierIni = dirname(__FILE__).DS.$this->projetNom.'.ini';
|
|
|
48 |
if (file_exists($fichierIni)) {
|
|
|
49 |
Config::charger($fichierIni);
|
|
|
50 |
} else {
|
|
|
51 |
$m = "Veuillez configurer le projet en créant le fichier '{$this->projetNom}.ini' ".
|
|
|
52 |
"dans le dossier du module de script du projet à partir du fichier '{$this->projetNom}.defaut.ini'.";
|
|
|
53 |
throw new Exception($m);
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
private function chargerStructureSql() {
|
|
|
58 |
$chemin = Config::get('chemins.structureSql');
|
36 |
jpm |
59 |
$requetes = Outils::extraireRequetes($chemin);
|
|
|
60 |
foreach ($requetes as $requete) {
|
|
|
61 |
$this->bdd->requeter($requete);
|
|
|
62 |
}
|
33 |
jpm |
63 |
}
|
|
|
64 |
|
|
|
65 |
private function chargerInseeD() {
|
|
|
66 |
$chemin = Config::get('chemins.inseeD');
|
|
|
67 |
$table = Config::get('tables.inseeD');
|
|
|
68 |
$requete = "LOAD DATA INFILE '$chemin' ".
|
|
|
69 |
"REPLACE INTO TABLE $table ".
|
|
|
70 |
'CHARACTER SET utf8 '.
|
|
|
71 |
'FIELDS '.
|
|
|
72 |
" TERMINATED BY ';' ".
|
|
|
73 |
" ENCLOSED BY '\"' ".
|
|
|
74 |
" ESCAPED BY '\\\' ".
|
|
|
75 |
'IGNORE 0 LINES';
|
|
|
76 |
$this->bdd->requeter($requete);
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
private function chargerOntologies() {
|
|
|
80 |
$chemin = Config::get('chemins.ontologies');
|
|
|
81 |
$table = Config::get('tables.ontologies');
|
|
|
82 |
$requete = "LOAD DATA INFILE '$chemin' ".
|
|
|
83 |
"REPLACE INTO TABLE $table ".
|
|
|
84 |
'CHARACTER SET utf8 '.
|
|
|
85 |
'FIELDS '.
|
|
|
86 |
" TERMINATED BY '\t' ".
|
|
|
87 |
" ENCLOSED BY '' ".
|
|
|
88 |
" ESCAPED BY '\\\' ".
|
|
|
89 |
'IGNORE 1 LINES';
|
|
|
90 |
$this->bdd->requeter($requete);
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
?>
|