5,10 → 5,8 |
* Options : |
* -t : Permet de tester le script sur un jeux réduit de données (indiquer le nombre de lignes). |
*/ |
class Nvjfl extends Script { |
class Nvjfl extends EfloreScript { |
|
private $bdd = null; |
private $projetNom = 'nvjfl'; |
private $nomsIndex = array(); |
private $numeroIndex = 1; |
|
18,8 → 16,7 |
public function executer() { |
// Lancement de l'action demandée |
try { |
$this->chargerConfigDuProjet(); |
$this->bdd = new Bdd(); |
$this->initialiserProjet('nvjfl'); |
|
$cmd = $this->getParametre('a'); |
switch ($cmd) { |
46,7 → 43,7 |
$this->chargerOntologies(); |
break; |
default : |
$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd)); |
throw new Exception("Erreur : la commande '$cmd' n'existe pas!"); |
} |
} catch (Exception $e) { |
$this->traiterErreur($e->getMessage()); |
53,25 → 50,6 |
} |
} |
|
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); |
} |
} |
|
/** |
* Charge le fichier en créant un id pour chaque nom vernaculaire. |
*/ |
82,10 → 60,10 |
fclose($fichierOuvert); |
foreach ($donnees as $donnee) { |
$requete = 'INSERT INTO '.Config::get('tables.nvjfl').' VALUES ('.implode(', ', $donnee).')'; |
$this->bdd->requeter($requete); |
$this->getBdd()->requeter($requete); |
|
$this->afficherAvancement("Insertion des noms vernaculaires dans la base de données"); |
if ($this->stopperLaBoucle()) { |
if ($this->stopperLaBoucle($this->getParametre('t'))) { |
break; |
} |
} |
92,17 → 70,6 |
echo "\n"; |
} |
|
private function stopperLaBoucle() { |
$stop = false; |
static $ligneActuelle = 1; |
if ($nbreLignesATester = $this->getParametre('t')) { |
if ($nbreLignesATester == $ligneActuelle++) { |
$stop = true; |
} |
} |
return $stop; |
} |
|
private function analyserFichier($fichierOuvert) { |
$donnees = array(); |
$entetesCsv = fgets($fichierOuvert); |
153,7 → 120,7 |
$champsProteges = array(); |
for ($i = 0; $i < 9; $i++) { |
$valeur = isset($champs[$i]) ? $champs[$i] : ''; |
$champsProteges[] = $this->bdd->proteger($valeur); |
$champsProteges[] = $this->getBdd()->proteger($valeur); |
} |
return $champsProteges; |
} |
169,7 → 136,7 |
" ENCLOSED BY '' ". |
" ESCAPED BY '\\\' ". |
'IGNORE 1 LINES'; |
$this->bdd->requeter($requete); |
$this->getBdd()->requeter($requete); |
} |
|
private function chargerBiblioLien() { |
183,7 → 150,7 |
" ENCLOSED BY '' ". |
" ESCAPED BY '\\\' ". |
'IGNORE 1 LINES'; |
$this->bdd->requeter($requete); |
$this->getBdd()->requeter($requete); |
} |
|
private function chargerOntologies() { |
197,7 → 164,7 |
" ENCLOSED BY '' ". |
" ESCAPED BY '\\\' ". |
'IGNORE 1 LINES'; |
$this->bdd->requeter($requete); |
$this->getBdd()->requeter($requete); |
} |
} |
?> |