Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 10 → Rev 11

/trunk/scripts/modules/nvjfl/Nvjfl.php
New file
0,0 → 1,52
<?php
/** Exemple lancement:
* /opt/lampp/bin/php -d memory_limit=3500M ~/web/nripts/cli.php nvjfl -a indexer -f /home/delphine/Documents/nvjfl_version_2007-10-29/NomsVernaculaires-2007-10-29/NomsVernaculaires-2007-10-29.csv
* Options :
* -f : indiquer le chemin du fichier à analyser
*/
class Nvjfl extends Script {
 
protected $parametres_autorises = array(
'-f' => array(true, null, 'Chemin du fichier à analyser'));
 
public function executer() {
// Lancement de l'action demandée
$cmd = $this->getParametre('a');
switch ($cmd) {
case 'indexer' :
$this->indexer();
break;
default :
$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
}
}
 
private function indexer() {
// créer un index pour un nom identique la clé primaire est composée de cet index + num_taxon + langue
$nomFichier = $this->getParametre('f');
if ($nomFichier) {
if (file_exists($nomFichier) === true) {
if ( $fichierOuvert = fopen($nomFichier, 'r') ) {
$this->bdd = new Bdd();
$nom_precedent = '';
$index = 0;
while ($ligne = fgets($fichierOuvert)) {
$champs = explode(';', $ligne);
if ($champs[3] != $nom_precedent) {
$index ++;
$nom_precedent = $champs[3];
}
$champs[0] = $index;
$this->bdd->requeter('INSERT INTO '.Config::get('bdd_table').' VALUES ('.implode(', ',$champs).');');
}
fclose($fichierOuvert);
} else {
$this->traiterErreur("Le fichier $nomFichier n'a pas pu être ouvert.");
}
} else {
$this->traiterErreur("Le fichier $nomFichier est introuvable.");
}
}
}
}
?>