13,21 → 13,18 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL |
* @version $Id$ |
*/ |
class Bdtfx extends Script { |
class Bdtfx extends EfloreScript { |
|
protected $bdd = null; |
protected $table = null; |
private $projetNom = 'bdtfx'; |
private $table = null; |
private $pasInsertion = 1000; |
private $departInsertion = 0; |
|
protected $pasInsertion = 1000; |
protected $departInsertion = 0; |
|
protected $parametres_autorises = array( |
'-t' => array(false, true, 'Permet de tester le script sur un jeux réduit de données (indiquer le nombre de lignes).')); |
|
public function executer() { |
try { |
$this->initialiser(); |
$this->initialiserProjet('bdtfx'); |
|
// Lancement de l'action demandée |
$cmd = $this->getParametre('a'); |
54,30 → 51,6 |
} |
} |
|
private function initialiser() { |
$this->chargerConfigDuProjet(); |
$this->bdd = new Bdd(); |
} |
|
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 chargerBdtfx() { |
$chemin = Config::get('chemins.bdtfx'); |
$table = Config::get('tables.bdtfx'); |
89,7 → 62,7 |
" ENCLOSED BY '' ". |
" ESCAPED BY '\\\' ". |
'IGNORE 1 LINES'; |
$this->bdd->requeter($requete); |
$this->getBdd()->requeter($requete); |
} |
|
private function genererNomSciHtml() { |
103,9 → 76,7 |
$this->lancerRequeteModification($nomsSciEnHtml); |
$this->departInsertion += $this->pasInsertion; |
$this->afficherAvancement("Insertion des noms scientifique au format HTML dans la base par paquet de {$this->pasInsertion} en cours"); |
if ($this->stopperLaBoucle()) { |
break; |
} |
if ($this->stopperLaBoucle($this->getParametre('t'))) break; |
} |
echo "\n"; |
} |
116,18 → 87,18 |
|
private function preparerTable() { |
$requete = "SHOW COLUMNS FROM {$this->table} LIKE 'nom_sci_html' "; |
$resultat = $this->bdd->recuperer($requete); |
$resultat = $this->getBdd()->recuperer($requete); |
if ($resultat === false) { |
$requete = "ALTER TABLE {$this->table} ". |
'ADD nom_sci_html VARCHAR( 500 ) '. |
'CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL '; |
$this->bdd->requeter($requete); |
$this->getBdd()->requeter($requete); |
} |
} |
|
private function recupererNbTotalTuples(){ |
$requete = "SELECT count(*) AS nb FROM {$this->table} "; |
$resultat = $this->bdd->recuperer($requete); |
$resultat = $this->getBdd()->recuperer($requete); |
return $resultat['nb']; |
} |
|
137,17 → 108,17 |
' nom_commercial, cultivar '. |
"FROM {$this->table} ". |
"LIMIT {$this->departInsertion},{$this->pasInsertion} "; |
$resultat = $this->bdd->recupererTous($requete); |
$resultat = $this->getBdd()->recupererTous($requete); |
return $resultat; |
} |
|
private function lancerRequeteModification($nomsSciHtm) { |
foreach ($nomsSciHtm as $id => $html) { |
$html = $this->bdd->proteger($html); |
$html = $this->getBdd()->proteger($html); |
$requete = "UPDATE {$this->table} ". |
"SET nom_sci_html = $html ". |
"WHERE num_nom = $id "; |
$resultat = $this->bdd->requeter($requete); |
$resultat = $this->getBdd()->requeter($requete); |
if ($resultat === false) { |
throw new Exception("Erreur d'insertion pour le tuple $id"); |
} |
154,15 → 125,6 |
} |
} |
|
private function stopperLaBoucle() { |
$stop = false; |
static $ligneActuelle = 1; |
if ($nbreLignesATester = $this->getParametre('t')) { |
if ($nbreLignesATester == $ligneActuelle++) { |
$stop = true; |
} |
} |
return $stop; |
} |
|
} |
?> |