Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 956 → Rev 1027

/tags/v5.5-arbousiere/scripts/modules/coste/Coste.php
New file
0,0 → 1,117
<?php
//declare(encoding='UTF-8');
/**
* Exemple de lancement du script : :
* /opt/lampp/bin/php cli.php coste -a chargerTous
*
* @category php 5.2
* @package eFlore/Scripts
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @copyright Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
* @version $Id$
*/
class Coste extends EfloreScript {
 
public function executer() {
try {
$this->initialiserProjet('coste');
 
// Lancement de l'action demandée
$cmd = $this->getParametre('a');
switch ($cmd) {
case 'chargerTous' :
$version = $this->getClasseVersion();
$version->chargerTous();
break;
case 'chargerStructureSql' :
$version = $this->getClasseVersion();
$version->chargerStructureSql();
break;
case 'chargerVersions' :
$version = $this->getClasseVersion();
$version->chargerVersions();
break;
case 'supprimerTous' :
$version = $this->getClasseVersion();
$version->supprimerTous();
break;
case 'creerDscTxt' :
$description = $this->getClasseDescription();
$description->genererDescriptionTxt();
break;
case 'statDscTxt' :
$description = $this->getClasseDescription();
$description->verifierDescriptionTxt();
break;
case 'correspondanceDsc' :
$description = $this->getClasseDescription();
$description->genererCorrespondance();
break;
case 'fusionIndex' :
$description = $this->getClasseIndex();
$description->fusionnerIndex();
break;
case 'uploadFichiersSp' :
$wiki = $this->getClasseWiki();
$wiki->uploaderFichiersSp();
break;
case 'downloadWiki' :
$wiki = $this->getClasseWiki();
$wiki->dowloaderPagesWiki();
break;
case 'uploadTxt' :
$wiki = $this->getClasseWiki();
$wiki->uploaderDansWikiEflore();
break;
case 'uploadIndex' :
$wiki = $this->getClasseWiki();
$wiki->uploaderIndexDansWikiEflore();
break;
case 'chargerTxt' :
$wiki = $this->getClasseWiki();
$wiki->chargerTxtDansWikiEflore();
break;
case 'chargerIndex' :
$wiki = $this->getClasseWiki();
$wiki->chargerIndexDansWikiEflore();
break;
default :
throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
}
} catch (Exception $e) {
$this->traiterErreur($e->getMessage());
}
}
 
private function getClasseVersion() {
$version = $this->getClasse('Versions');
return $version;
}
 
private function getClasseDescription() {
$description = $this->getClasse('Description');
return $description;
}
 
private function getClasseIndex() {
$index = $this->getClasse('Index');
return $index;
}
 
private function getClasseWiki() {
$wiki = $this->getClasse('Wiki');
return $wiki;
}
 
private function getClasse($classeNom) {
$conteneur = new Conteneur();
$conteneur->setParametre('-v', $this->getParametre('-v'));
$conteneur->setParametre('scriptChemin', $this->getScriptChemin());
require_once dirname(__FILE__).'/'.$classeNom.'.php';
$objet = new $classeNom($conteneur);
return $objet;
}
}
?>
/tags/v5.5-arbousiere/scripts/modules/coste/Description.php
New file
0,0 → 1,570
<?php
// commande : /opt/lampp/bin/php cli.php description_sp -a tester -n /home/jennifer/Tela-botanica_projets/Coste/descriptions/html
class Description {
 
const DOSSIER_V0 = '../../../donnees/coste/0.00/';
const DOSSIER_DSC_HTML = '../../../donnees/coste/descriptions/html/';
const DOSSIER_DSC_TXT = '../../../donnees/coste/descriptions/txt/';
const DOSSIER_LOG = 'log/';
 
private $auteurs = array();
private $dossierBase = '';
private $conteneur = null;
private $outils = null;
private $messages = null;
private $action = '';
private $nomFichier = '';
private $nomDossier = '';
private $listeFichiers = array();
private $fichierNum = '';
private $fichier = '';
private $log = '';
private $correspondance = array();
private $infosCorrespondanceBase = array(
'nom_sci' => '',
'auteur' => '',
'nom_addendum' => '',
'annee' => '',
'biblio_origine' => '',
'rang' => 290,
'nom_francais' => '',
'nom_coste' => '',
'auteur_coste' => '',
'biblio_coste' => '',
'num_nom_coste' => '',
'num_nom_retenu_coste' => '',
'num_tax_sup_coste' => '',
'tome' => '',
'page' => '',
'synonymie_coste' => '',
'flore_bdtfx_nn' => '',
'flore_bdtfx_nt' => '');
 
public function __construct(Conteneur $conteneur) {
mb_internal_encoding('UTF-8');
setlocale(LC_ALL, 'fr_FR.UTF-8');
$this->conteneur = $conteneur;
$this->outils = $conteneur->getOutils();
$this->messages = $conteneur->getMessages();
$this->dossierBase = dirname(__FILE__).'/';
}
 
public function genererDescriptionTxt() {
$this->chargerFichiers();
 
foreach ($this->listeFichiers as $this->fichierNum => $this->fichier) {
$this->messages->afficherAvancement("Création des descriptions au format txt");
$this->genererFichier();
}
echo "\n";
}
 
public function verifierDescriptionTxt() {
$this->chargerFichiers();
 
foreach ($this->listeFichiers as $this->fichierNum => $this->fichier) {
$this->messages->afficherAvancement("Analyse des descriptions");
$this->verifierFichier();
}
echo "\n";
$this->ecrireLogs();
}
 
public function genererCorrespondance() {
$this->chargerFichiers();
 
$this->ajouterLogSyno(implode("\t", array_keys($this->infosCorrespondanceBase)));
foreach ($this->listeFichiers as $this->fichierNum => $this->fichier) {
$this->messages->afficherAvancement("Création du fichier de correspondance");
$this->extraireInfosCorrespondance();
}
echo "\n";
 
$fichierTxt = $this->dossierBase.self::DOSSIER_V0.'index_general_sp.tsv';
$txtCorrespondance = $this->creerFichierCsvCorrespondance();
file_put_contents($fichierTxt, $txtCorrespondance);
 
ksort($this->auteurs);
foreach ($this->auteurs as $auteur => $nbre) {
$this->ajouterLogAuteur("$auteur\t$nbre");
}
 
$this->ecrireLogs();
}
 
 
private function chargerFichiers() {
$this->nomDossier = $this->dossierBase.self::DOSSIER_DSC_HTML;
if (file_exists($this->nomDossier) === true) {
if (is_dir($this->nomDossier)) {
if ($dossierOuvert = opendir($this->nomDossier)) {
while (($this->nomFichier = readdir($dossierOuvert)) !== false) {
if (! is_dir($this->nomFichier) && preg_match('/e([0-9]{4})\.htm/', $this->nomFichier, $match)) {
$this->listeFichiers[$match[1]] = $this->nomDossier.'/'.$this->nomFichier;
}
}
closedir($dossierOuvert);
} else {
$this->messages->traiterErreur("Le dossier {$this->nomDossier} n'a pas pu être ouvert.");
}
} else {
$this->messages->traiterErreur("{$this->nomDossier} n'est pas un dossier.");
}
} else {
$this->messages->traiterErreur("Le dossier {$this->nomDossier} est introuvable.");
}
 
asort($this->listeFichiers);
}
 
private function verifierFichier() {
$donnees = $this->analyserFichier();
$txt = $donnees['texte'];
$this->verifierOuvertureFermetureBalise($txt);
$this->verifierAbscenceEgale($txt);
$this->verifierNumero($txt);
// TODO : vérifier les noms vernauclaire qui sont abrégés
}
 
private function verifierOuvertureFermetureBalise($txt) {
$b_ouvert = substr_count($txt, '<B>');
$b_ferme = substr_count($txt, '</B>');
if ($b_ouvert != $b_ferme) {
$message = "{$this->fichierNum} contient $b_ouvert balises B ouvertes et $b_ferme fermées";
$this->ajouterLogAnalyse($message);
}
$i_ouvert = substr_count($txt, '<I>');
$i_ferme = substr_count($txt, '</I>');
if ($i_ouvert != $i_ferme) {
$message = "{$this->fichierNum} contient $i_ouvert balises I ouvertes et $i_ferme fermées";
$this->ajouterLogAnalyse($message);
}
}
 
private function verifierAbscenceEgale($txt) {
if (strripos($txt, '=') === false) {
$message = "{$this->fichierNum} ne contient pas le séparateur de phénologie (=)";
$this->ajouterLogAnalyse($message);
}
}
 
private function verifierNumero($txt) {
if (preg_match('/^<B>[0-9]{1,4}. – /', $txt) == 0) {
$message = "{$this->fichierNum} ne contient pas un numéro bien formaté";
$this->ajouterLogAnalyse($message);
}
}
 
private function extraireInfosCorrespondance() {
$donnees = $this->analyserFichier();
$infos = $this->infosCorrespondanceBase;
 
$titre = $donnees['titre'];
if (preg_match('/^Coste ([0-9]+) - ((?:(?! - ).)+) - F[0-9]+, (?:(?! - ).)+ - (G[0-9]+), T([123])[.]p([0-9]+)$/', $titre, $match)) {
$infos['num_nom_coste'] = $match[1];
$infos['num_nom_retenu_coste'] = $match[1];
$infos['nom_sci'] = $match[2];
$infos['num_tax_sup_coste'] = $match[3];
$infos['tome'] = $match[4];
$infos['page'] = $match[5];
} else {
$this->messages->traiterErreur("Le titre du fichier {$this->fichierNum} est mal formaté.");
}
 
$corres = $donnees['correspondance'];
if (preg_match('/^Bdnff ([0-9]+) - (?:(?! - ).)+ - (?:(?! - ).)+ - Tax=([0-9]+)$/', $corres, $match)) {
$infos['flore_bdtfx_nn'] = $match[1];
$infos['flore_bdtfx_nt'] = $match[2];
} else {
$this->messages->traiterErreur("La correspondance du fichier {$this->fichierNum} est mal formatée.");
}
 
$txt = $donnees['texte'];
$txt = $this->corrigerDescription($txt);
if (preg_match('/^<B>[0-9]{1,4}[.] – ([^<]+)<\/B> ([^–]*)– (?:<I>([^<]+)<\/I>[.] – |<I>([^<]+)<\/I>( \([^)]+\))[.] – |[A-Z]|<I>(?:Sous-|Espèce|Turion|Souche|Plante|Feuille|Racine))/u', $txt, $match)) {
$infos['nom_coste'] = trim($match[1]);
$infos['rang'] = $this->obtenirRangNom($infos['nom_coste']);
$infos['auteur_coste'] = trim($match[2]);
$infos['nom_francais'] = isset($match[3]) ? $match[3] : '';
$infos['nom_francais'] = isset($match[4]) && isset($match[5]) ? $match[4].$match[5] : $infos['nom_francais'];
if (strpos($infos['auteur_coste'], '(' ) !== false) {
if (preg_match('/^([^(]*)\(([^)]+)\)(?:[.]?| ; ((?:(?! – ).)+))$/', $infos['auteur_coste'], $match)) {
$infos['auteur_coste'] = $this->traiterAuteur(trim($match[1]));
$infos['auteur'] = $this->normaliserAuteur($infos['auteur_coste']);
$parentheseContenu = trim($match[2]);
if (preg_match('/^[0-9]+$/', $parentheseContenu)) {
$infos['annee'] = $parentheseContenu;
} else {
$infos['synonymie_coste'] = $parentheseContenu;
$infos['biblio_coste'] = isset($match[3]) ? trim($match[3]) : '';
}
} else {
$this->messages->traiterErreur("L'auteur du nom sciencitifique du fichier {$this->fichierNum} est mal formaté.");
}
}
} else {
$this->messages->traiterErreur("La texte du fichier {$this->fichierNum} est mal formaté.");
}
 
$this->correspondance[] = $infos;
 
if ($infos['synonymie_coste'] != '') {
$this->traiterSynonymie($infos);
}
}
 
private function normaliserAuteur($auteurCoste) {
$auteur = '';
if ($auteurCoste != '') {
$auteur = str_replace(' et ', ' & ', $auteurCoste);
}
return $auteur;
}
 
private function traiterSynonymie($infos) {
$synoCoste = $infos['synonymie_coste'];
$synoCoste = preg_replace('/, etc[.]$/', '', $synoCoste);
$synoCoste = preg_replace('/^et /', '', $synoCoste);
$synoCoste = preg_replace('/^(([A-Z][.]|[A-Z]{3,}) [A-Z]{3,}(?:(?! et ).+)) et ([A-Z]{3,}) ((?![A-Z]{3,}).+)$/', '$1 ; $2 $3 $4', $synoCoste);
$synoCoste = preg_replace('/ et ((?:[A-Z][.]|[A-Z]{3,}) [A-Z]{3,})/', ' ; $1', $synoCoste);
$synoCoste = preg_replace('/, ((?:(?!non |part[.]|an |G[.] G[.]|part[.]|centr[.])[^,]+))/', ' ;$1', $synoCoste);
 
$synonymes = explode(';', $synoCoste);
 
foreach ($synonymes as $num => $syno) {
$synoTraite = $this->traiterNomSyno($syno);
$nomSci = $this->obtenirNomSci($synoTraite, $infos, $synonymes, $num);
$rang = $this->obtenirRangNom($nomSci);
$complementNom = $this->obtenirComplementNom($synoTraite);
$auteurCoste = $this->obtenirAuteur($complementNom);
$auteur = $this->normaliserAuteur($auteurCoste);
$this->ajouterAuteur($auteur);
$biblioCoste = $this->obtenirBiblio($complementNom);
$annee = $this->extraireAnnee($complementNom);
 
$infosSyno = $this->infosCorrespondanceBase;
$infosSyno['nom_sci'] = $nomSci;
$infosSyno['auteur'] = $auteur;
$infosSyno['biblio_origine'] = $biblioCoste;
$infosSyno['annee'] = $annee;
$infosSyno['nom_addendum'] = $this->obtenirNomAddendum($syno);
 
$infosSyno['rang'] = $rang;
$infosSyno['nom_coste'] = $synoTraite;
$infosSyno['auteur_coste'] = $auteurCoste;
$infosSyno['biblio_coste'] = $biblioCoste;
$infosSyno['num_nom_coste'] = $infos['num_nom_coste'].'.'.($num + 1);
$infosSyno['num_nom_retenu_coste'] = $infos['num_nom_coste'];
$this->ajouterLogSyno(implode("\t", $infosSyno));
$this->correspondance[] = $infosSyno;
}
}
 
private function traiterNomSyno($syno) {
$syno = $this->nettoyerEspacesNomSyno($syno);
$syno = preg_replace('/^(?:avec|(?:compr|incl)[.]) /', '', $syno);
return $syno;
}
 
private function nettoyerEspacesNomSyno($syno) {
$syno = trim($syno);
$syno = trim($syno, ' ');
return $syno;
}
 
private function obtenirComplementNom($syno) {
$complementNom = '';
if (preg_match('/^(?:[^ ]+ [^ ]+ (?:(?:var|V)[.] [^ ]+|STELATUM|MINUS)|[^ ]+ [^ ]+) (.+)$/', $syno, $match)) {
$complementNom = $match[1];
}
return $complementNom;
}
 
private function obtenirBiblio($complementNom) {
$biblioCoste = '';
if (preg_match("/ (p[.] [0-9]{1,}|in .+||Fl[.] fr[.]|(?: Sp[.])? ed[.] [1-2])$/", $complementNom, $match)) {
$biblioCoste = $match[1];
}
return $biblioCoste;
}
 
private function extraireAnnee($complementNom) {
$annee = '';
if (preg_match('/(?:^| )([0-9]+)$/', $complementNom, $match)) {
$annee = $match[1];
}
return $annee;
}
 
private function obtenirAuteur($complementNom) {
$auteurCoste = '';
if ($complementNom != '') {
if (preg_match("/^((?!(?:auct.+|(?:, )?(?:non|an) .+|p[.] p[.])$).+)$/", $complementNom, $match)) {
$auteurCoste = $this->traiterAuteur($match[1]);
} else {
$message = "Impossible de récupérer l'auteur pour le complément de nom ($complementNom).";
$this->ajouterLogProbleme($message);
}
}
return $auteurCoste;
}
 
private function traiterAuteur($auteurCoste) {
$auteur = '';
if ($auteurCoste != '') {
$remplacementTxt = array(' p. p.', ' saltem part.', 'Fl. fr.');
$auteurCoste = str_replace($remplacementTxt, '', $auteurCoste);
$remplacementsRegExp = array(
' [0-9]{4}',
'[^ ]+ et auct[.], .+',
' auct.+',
',? part[.]',
' p[.] [0-9]{1,}',
' in .+|,? (?:non|an) .+',
'(?: Sp[.])? ed[.] [1-2]');
$auteur = preg_replace('/(?:'.implode('|', $remplacementsRegExp).')$/', '', $auteurCoste);
}
return $auteur;
}
 
private function ajouterAuteur($auteur) {
if (!isset($this->auteurs[$auteur])) {
$this->auteurs[$auteur] = 1;
} else {
$this->auteurs[$auteur]++;
}
}
 
private function obtenirNomAddendum($syno) {
$syno = $this->nettoyerEspacesNomSyno($syno);
$nomAddendum = array();
if (preg_match('/^((?:compr|incl)[.]) /', $syno, $match)) {
$nomAddendum[] = '['.$match[1].']';
}
if (preg_match('/ ([^ ]+ et auct[.], .+)$/', $syno, $match)) {
$nomAddendum[] = '['.$match[1].']';
} elseif (preg_match('/ (auct[.],? .+)$/', $syno, $match)) {
$nomAddendum[] = '['.$match[1].']';
} else if (preg_match('/,? ((?:non|an) .+)$/', $syno, $match)) {
$nomAddendum[] = '['.$match[1].']';
} else if (preg_match('/ (p[.] p[.])$/', $syno, $match)) {
$nomAddendum[] = '['.$match[1].']';
} else if (preg_match('/ (saltem part[.])$/', $syno, $match)) {
$nomAddendum[] = '['.$match[1].']';
} else if (preg_match('/,? (part[.])$/', $syno, $match)) {
$nomAddendum[] = '['.$match[1].']';
}
 
$nomAddendum = implode(' ; ', $nomAddendum);
return $nomAddendum;
}
 
private function remplacerAbreviationGenre($syno, $infos, $synonymes, $num) {
$nomSci = $syno;
 
if (preg_match('/^(([A-Zƌ])[.]) /', $syno, $matchSyno)) {
if ($matchSyno[2] == substr($infos['nom_coste'], 0, 1)) {
if (preg_match('/^([^ ]+) /', $infos['nom_coste'], $matchNomRetenu)) {
$nomSci = str_replace($matchSyno[1], $matchNomRetenu[1], $syno);
}
} else {
$synoPrecedent = $this->obtenirSynoAvecGenreComplet($synonymes, $num);
 
if ($matchSyno[2] == substr($synoPrecedent, 0, 1)) {
if (preg_match('/^([^ ]+) /', $synoPrecedent, $matchSynoPrec)) {
$nomSci = str_replace($matchSyno[1], $matchSynoPrec[1], $syno);
}
} else {
$message = "L'initiale du synonyme ($syno) ne correspondant pas au nom retenu {$infos['num_nom_coste']} ({$infos['nom_coste']}) ".
"ni au synonyme précédent ($synoPrecedent).";
$this->ajouterLogProbleme($message);
}
}
}
return $nomSci;
}
 
private function obtenirSynoAvecGenreComplet($synonymes, $num) {
$synoPrecedent = '';
$synoOk = false;
while ($synoOk == false) {
if ($num < 0) {
$synoOk = true;
}
$synoPrecedent = $this->obtenirSynoPrecedent($synonymes, $num);
if (preg_match('/^[A-Zƌ][.] /', $synoPrecedent)) {
$num = $num - 1;
} else {
$synoOk = true;
}
}
return $synoPrecedent;
}
 
private function obtenirSynoPrecedent($synonymes, $num) {
$synoPrecedent = '';
if (isset($synonymes[($num - 1 )])) {
$synoPrecedent = $this->traiterNomSyno($synonymes[($num - 1 )]);
}
return $synoPrecedent;
}
 
 
private function obtenirNomSci($syno, $infos, $synonymes, $num) {
$nomSci = $this->remplacerAbreviationGenre($syno, $infos, $synonymes, $num);
 
if (preg_match('/^([^ ]+) ([^ ]+) (?:(?:var|V)[.] ([^ ]+)|(STELATUM||MINUS) )/', $nomSci, $match)) {
$genre = $this->normaliserGenre($match[1]);
$sp = $this->normaliserEpithete($match[2]);
$infrasp = isset($match[4]) ? $match[4] : $match[3];
$infrasp = $this->normaliserEpithete($infrasp);
$nomSci = "$genre $sp var. $infrasp";
} else if (preg_match('/^([^ ]+) ([^ ]+)(?: |$)/', $nomSci, $match)) {
$genre = $this->normaliserGenre($match[1]);
$sp = $this->normaliserEpithete($match[2]);
$nomSci = "$genre $sp";
} else {
$message = "Le synonyme ($nomSci) du nom {$infos['num_nom_coste']} a une structure étrange.";
$this->ajouterLogProbleme($message);
}
return $nomSci;
}
 
private function normaliserGenre($genre) {
$genre = mb_convert_case(mb_strtolower($genre), MB_CASE_TITLE);
$genre = str_replace('Æ', 'æ', $genre);
return $genre;
}
 
private function normaliserEpithete($sp) {
$sp = mb_strtolower($sp);
$sp = str_replace('Æ', 'æ', $sp);
return $sp;
}
 
private function obtenirRangNom($syno) {
$rang = 290;
if (strpos($syno, ' var. ')) {
$rang = 340;
}
return $rang;
}
 
private function creerFichierCsvCorrespondance() {
$lignes[] = implode("\t", array_keys($this->infosCorrespondanceBase));
foreach ($this->correspondance as $infos) {
$lignes[] = implode("\t", $infos);
}
 
$txt = '';
$txt = implode("\n", $lignes);
return $txt;
}
 
private function genererFichier() {
$donnees = $this->analyserFichier();
 
$txt = $this->nettoyerDescription($donnees['texte']);
$txt = $this->corrigerDescription($txt);
$txt = $this->remplacerHtmlParSyntaxeWiki($txt);
$fichierTxt = $this->dossierBase.self::DOSSIER_DSC_TXT.$this->fichierNum.'.txt';
file_put_contents($fichierTxt, $txt);
 
unset($donnees['texte']);
$txt = implode("\n", $donnees);
$fichierTxt = $this->dossierBase.self::DOSSIER_DSC_TXT.$this->fichierNum.'.json';
file_put_contents($fichierTxt, $txt);
}
 
private function analyserFichier() {
$donnees = array('titre' => '', 'texte' => '', 'correspondance' => '');
if ($fichierOuvert = fopen($this->fichier, 'r')) {
$i = 1;
while ($ligne = fgets($fichierOuvert)) {
if ($i == 24) {
$donnees['titre'] = $this->supprimerHtml($ligne);
} elseif ($i >= 45 && $i <= 60) {
$donnees['texte'] .= $this->traiterLigneDescription($ligne);
} elseif ($i >= 61 && preg_match('/Bdnff /ui', $ligne)) {
$donnees['correspondance'] = $this->supprimerHtml($ligne);
}
$i++;
}
fclose($fichierOuvert);
} else {
$this->messages->traiterErreur("Le fichier {$this->fichier} n'a pas pu être ouvert.");
}
return $donnees;
}
 
private function supprimerHtml($txt) {
$txt = strip_tags($txt,'<b>,<i>');
$txt = str_replace('&#173;', '', $txt);
$txt = str_ireplace('&nbsp;', ' ', $txt);
$txt = trim($txt);
$txt = preg_replace('/^<\/I>/', '', $txt);
$txt = html_entity_decode($txt, ENT_NOQUOTES, 'UTF-8');
return $txt;
}
 
private function traiterLigneDescription($txt) {
$txt = $this->supprimerHtml($txt);
$txt = $txt."\n";
return $txt;
}
 
private function nettoyerDescription($txt) {
$txt = preg_replace("/\n{2,}+/", "\n", $txt);
$txt = trim($txt);
return $txt;
}
 
private function corrigerDescription($txt) {
$txt = preg_replace("/– <I>([^.]+?)[.] – <\/I>/", "– <I>$1</I>. – ", $txt);
$txt = preg_replace("/– <I>([^.]+?)[.] – ([A-Z])<\/I>/", "– <I>$1</I>. – $2", $txt);
$txt = preg_replace("/– <I>([^.]+?) – <\/I>/", "– <I>$1</I>. – ", $txt);
return $txt;
}
 
private function remplacerHtmlParSyntaxeWiki($txt) {
$txt = str_replace(array('<B>', '</B>'), '**', $txt);
$txt = str_replace(array('<I>', '</I>'), '//', $txt);
return $txt;
}
 
private function ajouterLogAnalyse($txt) {
if (isset($this->log['analyse']) == false) {
$this->log['analyse'] = '';
}
$this->log['analyse'] .= "$txt\n";
}
 
private function ajouterLogSyno($txt) {
if (isset($this->log['synonymes']) == false) {
$this->log['synonymes'] = '';
}
$this->log['synonymes'] .= "$txt\n";
}
 
private function ajouterLogAuteur($txt) {
if (isset($this->log['auteurs']) == false) {
$this->log['auteurs'] = '';
}
$this->log['auteurs'] .= "$txt\n";
}
 
private function ajouterLogProbleme($txt) {
if (isset($this->log['problemes']) == false) {
$this->log['problemes'] = '';
}
$this->log['problemes'] .= "$txt\n";
}
 
private function ecrireLogs() {
foreach ($this->log as $nom => $log) {
$fichier = $this->dossierBase.self::DOSSIER_LOG.$nom.'.log';
file_put_contents($fichier, $log);
}
}
}
?>
/tags/v5.5-arbousiere/scripts/modules/coste/Wiki.php
New file
0,0 → 1,251
<?php
class Wiki {
const DOSSIER_V2 = '../../../donnees/coste/2.00/';
const DOSSIER_DSC_TXT = '../../../donnees/coste/descriptions/txt/';
 
private $URL_WIKI = '';
private $URL_WIKI_EFLORE = '';
private $conteneur = null;
private $outils = null;
private $messages = null;
private $restClient = null;
private $bdd = null;
private $dossierBase = '';
private $index = array();
 
public function __construct(Conteneur $conteneur) {
mb_internal_encoding('UTF-8');
setlocale(LC_ALL, 'fr_FR.UTF-8');
$this->conteneur = $conteneur;
$this->URL_WIKI = $this->conteneur->getParametre('wiki.travail');
$this->URL_WIKI_EFLORE = $this->conteneur->getParametre('wiki.eflore');
$this->outils = $conteneur->getOutils();
$this->messages = $conteneur->getMessages();
$this->restClient = $conteneur->getRestClient();
$this->bdd = $conteneur->getBdd();
$this->dossierBase = dirname(__FILE__).'/';
}
 
public function uploaderFichiersSp() {
$this->chargerIndex();
$envoyes = array();
foreach ($this->index as $nom) {
$tag = $nom['page_wiki_dsc'];
if (isset($envoyes[$tag]) == false && preg_match('/^Esp([0-9]{4})/', $tag, $match)) {
$fichier = $this->dossierBase.self::DOSSIER_DSC_TXT.$match[1].'.txt';
if (file_exists($fichier) === true) {
$txt = file_get_contents($fichier);
$donnees = array('pageTag' => $tag, 'pageContenu' => $txt);
$this->restClient->ajouter($this->URL_WIKI, $donnees);
$envoyes[$tag] = 'OK';
} else {
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
}
}
$this->messages->afficherAvancement("Upload des fichiers d'espèce dans le wikini");
}
echo "\n";
}
 
public function dowloaderPagesWiki() {
$this->chargerIndex();
$envoyes = array();
foreach ($this->index as $nom) {
$tagDsc = $nom['page_wiki_dsc'];
$tagCle = $nom['page_wiki_cle'];
if (isset($envoyes[$tagDsc]) == false) {
$url = $this->URL_WIKI.'/'.$tagDsc;
$txt = $this->telechargerTxt($url);
$fichier = $this->dossierBase.self::DOSSIER_V2.'dsc/'.$tagDsc.'.txt';
if (file_put_contents($fichier, $txt)) {
$envoyes[$tagDsc] = 'OK';
}
}
if (isset($envoyes[$tagCle]) == false) {
$url = $this->URL_WIKI.'/'.$tagCle;
$txt = $this->telechargerTxt($url);
$fichier = $this->dossierBase.self::DOSSIER_V2.'cle/'.$tagCle.'.txt';
if (file_put_contents($fichier, $txt)) {
$envoyes[$tagCle] = 'OK';
}
}
$this->messages->afficherAvancement("Download des fichiers en cours");
}
echo "\n";
}
 
public function uploaderDansWikiEflore() {
$this->chargerIndex();
$envoyes = array();
 
foreach ($this->index as $nom) {
$tagDsc = $nom['page_wiki_dsc'];
if (isset($envoyes[$tagDsc]) == false) {
$fichier = $this->dossierBase.self::DOSSIER_V2.'dsc/'.$tagDsc.'.txt';
if (file_exists($fichier) === true) {
$txt = file_get_contents($fichier);
$this->envoyerPage($tagDsc, $txt);
$envoyes[$tagDsc] = 'OK';
} else {
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
}
}
 
$tagCle = $nom['page_wiki_cle'];
if (isset($envoyes[$tagCle]) == false) {
$fichier = $this->dossierBase.self::DOSSIER_V2.'cle/'.$tagCle.'.txt';
if (file_exists($fichier) === true) {
$txt = file_get_contents($fichier);
$this->envoyerPage($tagCle, $txt);
$envoyes[$tagCle] = 'OK';
} else {
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
}
}
$this->messages->afficherAvancement("Upload des textes dans le wikini eFlore");
}
echo "\n";
}
 
public function chargerTxtDansWikiEflore() {
$this->chargerIndex();
$envoyes = array();
foreach ($this->index as $nom) {
$tagDsc = $nom['page_wiki_dsc'];
if ($tagDsc != '' && isset($envoyes[$tagDsc]) == false) {
$fichier = $this->dossierBase.self::DOSSIER_V2.'dsc/'.$tagDsc.'.txt';
if (file_exists($fichier) === true) {
$txt = file_get_contents($fichier);
$this->enregistrerPage($tagDsc, $txt);
$envoyes[$tagDsc] = 'OK';
} else {
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
}
}
 
$tagCle = $nom['page_wiki_cle'];
if ($tagCle != '' && isset($envoyes[$tagCle]) == false) {
$fichier = $this->dossierBase.self::DOSSIER_V2.'cle/'.$tagCle.'.txt';
if (file_exists($fichier) === true) {
$txt = file_get_contents($fichier);
$this->enregistrerPage($tagCle, $txt);
$envoyes[$tagCle] = 'OK';
} else {
$this->messages->traiterErreur("Le fichier $fichier est introuvable.");
}
}
$this->messages->afficherAvancement("Enregistrement des textes dans le wikini eFlore");
}
echo "\n";
}
 
public function chargerIndexDansWikiEflore() {
$index = $this->creerIndex();
foreach ($index as $titre => $txt) {
$this->enregistrerPage($titre, $txt);
}
}
 
public function uploaderIndexDansWikiEflore() {
$index = $this->creerIndex();
foreach ($index as $titre => $txt) {
$this->envoyerPage($titre, $txt);
}
}
 
public function creerIndex() {
$this->chargerIndex();
$envoyes = array();
$pageIndexFamille = "==Index Famille Coste==\n\n";
$pageIndexGenre = "==Index Genre Coste==\n\n";
$pageIndexEspece = "==Index Espèce Coste==\n\n";
foreach ($this->index as $nom) {
$indentation = $this->getIndentationTxtLien($nom);
$txtLien = $this->getTxtLienGenerique($nom);
$img = $nom['image'];
$tagDsc = $nom['page_wiki_dsc'];
if (isset($envoyes[$tagDsc]) == false) {
//$fichier = $this->dossierBase.self::DOSSIER_V2.'dsc/'.$tagDsc.'.txt';
if ($nom['rang'] <= 180) {
$pageIndexFamille .= "$indentation- [[$tagDsc $txtLien]]\n";
} elseif ($nom['rang'] == 220) {
$pageIndexGenre .= "$indentation- [[$tagDsc $txtLien]]\n";
} else {
$pageIndexEspece .= "$indentation- [[$tagDsc $txtLien]] - [[http://www.tela-botanica.org/eflore/donnees/coste/2.00/img/$img]]\n";
}
$envoyes[$tagDsc] = 'OK';
}
 
$tagCle = $nom['page_wiki_cle'];
if (isset($envoyes[$tagCle]) == false) {
//$fichier = $this->dossierBase.self::DOSSIER_V2.'cle/'.$tagCle.'.txt';
$indentation = $indentation.' ';
if ($nom['rang'] <= 180) {
$pageIndexFamille = rtrim($pageIndexFamille, "\n");
$pageIndexFamille .= " - [[$tagCle Clé]]\n";
} elseif ($nom['rang'] == 220) {
$pageIndexGenre = rtrim($pageIndexGenre, "\n");
$pageIndexGenre .= " - [[$tagCle Clé]]\n";
}
$envoyes[$tagCle] = 'OK';
}
$this->messages->afficherAvancement("Création des pages d'index pour le wikini eFlore");
}
echo "\n";
 
$index = array('IndexFamille' => $pageIndexFamille, 'IndexGenre' => $pageIndexGenre, 'IndexEspece' => $pageIndexEspece);
return $index;
}
 
private function getIndentationTxtLien($nom) {
$rangs = array('Reg' => 1, 'Emb' => 2, 'Cla' => 3, 'Fam' => 4, 'Gen' => 5, 'Esp' => 6);
$indentation = '';
if (preg_match('/^(Reg|Emb|Cla|Fam|Gen|Esp)[0-9]+/', $nom['page_wiki_dsc'], $match)) {
$type = $match[1];
$indentation = str_repeat(' ', $rangs[$type]);
}
return $indentation;
}
 
private function getTxtLienGenerique($nom) {
$rangs = array('Reg' => 'Règne', 'Emb' => 'Embranchement', 'Cla' => 'Classe', 'Fam' => 'Famille',
'Gen' => 'Genre', 'Esp' => 'Espèce');
$nomSci = $nom['nom_sci'];
$nomCoste = $nom['nom_coste'];
$txtLien = '';
if (preg_match('/^(Reg|Emb|Cla|Fam|Gen|Esp)([0-9]*)/', $nom['page_wiki_dsc'], $match)) {
$numCoste = $match[2];
$type = $match[1];
$nomRang = $rangs[$type];
$nom = ($type == 'Fam') ? $nomCoste : $nomSci;
$txtLien = "$nomRang $numCoste - $nom";
}
return $txtLien;
}
 
private function envoyerPage($titre, $txt) {
$donnees = array('pageTag' => $titre, 'pageContenu' => $txt);
$this->restClient->ajouter($this->URL_WIKI_EFLORE, $donnees);
}
 
private function enregistrerPage($titre, $txt) {
$titre = $this->bdd->proteger($titre);
$time = $this->bdd->proteger(date('Y-m-d H:i:s'));
$txt = $this->bdd->proteger($txt);
$requete = "INSERT INTO `coste_pages` (`tag`, `time`, `body`, `body_r`, `owner`, `user`, `latest`, `handler`, `comment_on`) VALUES ".
"($titre, $time, $txt, '', '', 'ScriptEflore', 'Y', 'page', '')";
$this->bdd->requeter($requete);
}
 
private function telechargerTxt($url) {
$json = $this->restClient->consulter($url);
$donnees = json_decode($json, true);
return $donnees['texte'];
}
 
private function chargerIndex() {
$indexTxt = $this->dossierBase.self::DOSSIER_V2.'coste_v2_00.tsv';
$this->index = $this->outils->transformerTxtTsvEnTableau($indexTxt);
}
}
?>
/tags/v5.5-arbousiere/scripts/modules/coste/coste.ini
New file
0,0 → 1,30
; Ajouter les nouvelles version à la suite dans versions et versionsDonnees.
version="2_00"
versionDonnees="2.00"
dossierTsv = "{ref:dossierDonneesEflore}coste/{ref:versionDonnees}/"
dossierTsvTpl = "{ref:dossierDonneesEflore}coste/%s/"
dossierSql = "{ref:dossierDonneesEflore}coste/"
 
[tables]
costeMeta = "coste_meta"
coste = "coste_v{ref:version}"
costeTpl = "coste_v%s"
 
[fichiers]
structureSqlVersion = "coste_v{ref:version}.sql"
structureSqlVersionTpl = "coste_v%s.sql"
coste = "coste_v{ref:version}.tsv"
costeTpl = "coste_v%s.tsv"
costeWikiniTpl = "coste_wikini_v%s.sql"
 
[chemins]
structureSql = "{ref:dossierSql}{ref:fichiers.structureSql}"
structureSqlVersion = "{ref:dossierTsv}{ref:fichiers.structureSqlVersion}"
structureSqlVersionTpl = "{ref:dossierTsvTpl}{ref:fichiers.structureSqlVersionTpl}"
coste = "{ref:dossierTsv}{ref:fichiers.coste}"
costeTpl = "{ref:dossierTsvTpl}{ref:fichiers.costeTpl}"
costeWikiniTpl = "{ref:dossierTsvTpl}{ref:fichiers.costeWikiniTpl}"
 
[wiki]
travail = "http://www.tela-botanica.org/wikini/florecoste/api/rest/0.5/pages"
eflore = "http://www.tela-botanica.org/wikini/coste/api/rest/0.5/pages"
/tags/v5.5-arbousiere/scripts/modules/coste/Index.php
New file
0,0 → 1,329
<?php
class Index {
 
const DOSSIER_V0 = '../../../donnees/coste/0.00/';
const DOSSIER_V2 = '../../../donnees/coste/2.00/';
 
private $conteneur = null;
private $outils = null;
private $messages = null;
private $generateur = null;
private $dossierBase = '';
private $spIndex = array();
private $supraSpIndex = array();
private $imgIndex = array();
private $indexFinal = array();
private $tableauParDefaut = array();
private $nbreTaxonInf = array();
private $enteteFinal = array(
'num_nom',
'num_nom_retenu',
'num_tax_sup',
'rang',
'nom_sci',
'nom_supra_generique',
'genre',
'epithete_infra_generique',
'epithete_sp',
'type_epithete',
'epithete_infra_sp',
'cultivar_groupe',
'cultivar',
'nom_commercial',
'auteur',
'annee',
'biblio_origine',
'notes',
'nom_addendum',
'nom_francais',
'nom_coste',
'auteur_coste',
'biblio_coste',
'num_nom_coste',
'num_nom_retenu_coste',
'num_tax_sup_coste',
'synonymie_coste',
'tome',
'page',
'nbre_taxons',
'flore_bdtfx_nn',
'flore_bdtfx_nt',
'image',
'image_auteur',
'page_wiki_dsc',
'page_wiki_cle',
'nom_sci_html');
 
public function __construct(Conteneur $conteneur) {
mb_internal_encoding('UTF-8');
setlocale(LC_ALL, 'fr_FR.UTF-8');
$this->conteneur = $conteneur;
$this->outils = $conteneur->getOutils();
$this->messages = $conteneur->getMessages();
$this->generateur = $conteneur->getGenerateurNomSciHtml();
$this->dossierBase = dirname(__FILE__).'/';
}
 
public function fusionnerIndex() {
$this->chargerIndexSp();
$this->chargerIndexSupraSp();
$this->initialiserTableauLigneIndexFinal();
$this->creerIndexFinal();
$this->insererCorrections();
$this->ajouterChampsDansIndexFinal();
$this->ajouteurAuteurImage();
$this->decomposerNomSci();
$this->ajouteurNomSciHtml();
$this->creerFichierCsvIndexFinal();
}
 
private function chargerIndexSp() {
$spIndexFichier = $this->dossierBase.self::DOSSIER_V0.'index_general_sp.tsv';
$index = $this->outils->transformerTxtTsvEnTableau($spIndexFichier);
$index = $this->reindexerParNumNomCoste($index);
foreach ($index as $numNomCoste => $infos) {
$numTaxSup = '';
if ($infos['num_nom_coste'] == $infos['num_nom_retenu_coste']) {
$numTaxSup = $infos['num_tax_sup_coste'];
} else {
$infosNomRetenu = $index[$infos['num_nom_retenu_coste']];
$numTaxSup = $infosNomRetenu['num_tax_sup_coste'];
}
$this->spIndex[$numTaxSup][] = $infos;
}
}
 
private function reindexerParNumNomCoste($index) {
$nouvelIndex = array();
foreach ($index as $infos) {
$nouvelIndex[$infos['num_nom_coste']] = $infos;
}
return $nouvelIndex;
}
 
private function chargerIndexSupraSp() {
$infraSpIndexFichier = $this->dossierBase.self::DOSSIER_V0.'index_general.tsv';
$this->supraSpIndex = $this->outils->transformerTxtTsvEnTableau($infraSpIndexFichier);
foreach ($this->supraSpIndex as $cle => $infos) {
$this->supraSpIndex[$cle]['num_nom_retenu_coste'] = $infos['num_nom_coste'];
}
}
 
private function initialiserTableauLigneIndexFinal() {
$this->tableauParDefaut = array();
foreach ($this->enteteFinal as $cle) {
$this->tableauParDefaut[$cle] = '';
}
}
 
private function creerIndexFinal() {
foreach ($this->supraSpIndex as $infos) {
$this->ajouterDansIndexFinal($infos);
if (preg_match('/^G[0-9]+$/', $infos['num_nom_coste'])) {
foreach ($this->spIndex[$infos['num_nom_coste']] as $infosSp) {
$this->ajouterDansIndexFinal($infosSp);
}
}
}
}
 
private function ajouterDansIndexFinal($infos) {
$infos = array_merge($this->tableauParDefaut, $infos);
$infos['num_nom'] = (count($this->indexFinal) + 1);
$this->indexFinal[$infos['num_nom_coste']] = $infos;
}
 
private function ajouterChampsDansIndexFinal() {
$this->genererNbreTaxons();
foreach ($this->indexFinal as $nnc => $infos) {
if ($infos['num_nom_coste'] == $infos['num_nom_retenu_coste']) {
$infos['num_nom_retenu'] = $infos['num_nom'];
if ($nnc != 'R') {
$nomSuperieur = $this->indexFinal[$infos['num_tax_sup_coste']];
$infos['num_tax_sup'] = $nomSuperieur['num_nom'];
}
$nomRetenu = $infos;
} else {
$nomRetenu = $this->indexFinal[$infos['num_nom_retenu_coste']];
$infos['num_nom_retenu'] = $nomRetenu['num_nom'];
$infos['page'] = $nomRetenu['page'];
$infos['tome'] = $nomRetenu['tome'];
}
$infos['image'] = $this->obtenirNomFichierImg($nomRetenu);
$infos['nbre_taxons'] = $this->obtenirNbreTaxon($infos);
$nomRetenu['nbre_taxons'] = $infos['nbre_taxons'];
$infos['page_wiki_dsc'] = $this->genererPageWikiDsc($nomRetenu);
$infos['page_wiki_cle'] = $this->genererPageWikiCle($nomRetenu);
 
$this->indexFinal[$nnc] = $infos;
}
}
 
private function genererNbreTaxons() {
foreach ($this->indexFinal as $infos) {
if ($infos['num_tax_sup_coste'] != '') {
if (isset($this->nbreTaxonInf[$infos['num_tax_sup_coste']])) {
$this->nbreTaxonInf[$infos['num_tax_sup_coste']] += 1;
} else {
$this->nbreTaxonInf[$infos['num_tax_sup_coste']] = 1;
}
}
}
}
 
private function genererPageWikiDsc($infos) {
$prefixe = $this->genererPrefixePage($infos);
if ($infos['rang'] == '180') {
$nomSci = str_replace(' ', '', ucwords(strtolower($infos['nom_coste'])));
} else {
$nomSci = str_replace(' ', '', ucwords(strtolower($infos['nom_sci'])));
}
$pageWiki = $prefixe.$nomSci;
return $pageWiki;
}
 
private function genererPageWikiCle($infos) {
$pageWiki = '';
if ($infos['nbre_taxons'] > 1) {
$prefixe = $this->genererPrefixePage($infos);
if ($infos['rang'] == '20') {
$pageWiki = $prefixe.'TabClaEtEmb';
} elseif ($infos['rang'] == '40' && ($infos['num_nom_coste'] == 'E2' || $infos['num_nom_coste'] == 'E3')) {
$pageWiki = $prefixe.'TabFam';
} else if ($infos['rang'] == '80') {
$pageWiki = $prefixe.'TabFam';
} else if ($infos['rang'] == '180') {
$pageWiki = $prefixe.'TabGen';
} else if ($infos['rang'] == '220') {
$pageWiki = $prefixe.'TabSp';
}
}
return $pageWiki;
}
 
private function genererPrefixePage($infos) {
$prefixe = '';
$num = preg_replace('/^[a-z]*([0-9]+)(?:[.][0-9a-z]|)$/i', '$1', $infos['num_nom_coste']);
if (preg_match('/^([0-9]+)[.][0-9a-z]$/i', $infos['num_nom_coste'], $match)) {
$num = sprintf('%04s', $match[1]);
} else if ($infos['rang'] == 20 ) {
$num = '';
} else if ($infos['rang'] < 80 ) {
$num = sprintf('%02s', $num);
} else if ($infos['rang'] < 290 ) {
$num = sprintf('%03s', $num);
} else {
$num = sprintf('%04s', $num);
}
$rangsTxt = array('20' => 'Reg', '40' => 'Emb', '80' => 'Cla', '180' => 'Fam', '220' => 'Gen', '290' => 'Esp', '340' => 'Var');
$rang = $rangsTxt[$infos['rang']];
 
$prefixe = $rang.$num;
return $prefixe;
}
 
private function obtenirNbreTaxon($infos) {
$nbre = '';
if (isset($this->nbreTaxonInf[$infos['num_nom_coste']])) {
$nbre = $this->nbreTaxonInf[$infos['num_nom_coste']];
}
return $nbre;
}
 
private function obtenirNomFichierImg($infos) {
$img = '';
if ($infos['rang'] == '290') {
$prefixe = preg_replace('/[.][a-z]$/', '', $infos['num_nom_retenu']);
$img = $prefixe.'.png';
}
return $img;
}
 
private function ajouteurAuteurImage() {
$this->chargerAuteurImg();
foreach ($this->indexFinal as $nnc => $infos) {
$infos['image_auteur'] = $this->imgIndex[$infos['image']];
$this->indexFinal[$nnc] = $infos;
}
}
 
private function chargerAuteurImg() {
$imgIndexFichier = $this->dossierBase.self::DOSSIER_V0.'coste_images_auteur_correspondance_bdnff.tsv';
$index = $this->outils->transformerTxtTsvEnTableau($imgIndexFichier);
foreach ($index as $infos) {
$id = $infos['id_image'];
$this->imgIndex[$id] = $infos['auteur'];
}
}
 
private function decomposerNomSci() {
$majuscule = "[ÆŒA-Z]";
$epithete = "[æœïa-z-]+";
foreach ($this->indexFinal as $nnc => $infos) {
$id = $infos['num_nom_coste'];
$nomSci = $infos['nom_sci'];
$rang = $infos['rang'];
if ($rang < 220) {
$infos['nom_supra_generique'] = $nomSci;
} else if ($rang == 220) {
$infos['genre'] = $nomSci;
} else if ($rang == 290) {
if (preg_match("/^($majuscule$epithete) ($epithete)$/", $nomSci, $match)) {
$infos['genre'] = $match[1];
$infos['epithete_sp'] = $match[2];
} else {
$this->messages->traiterErreur("Le nom $nomSci ($id) de rang $rang n'est pas standard.");
}
} else if ($rang == 340) {
if (preg_match("/^($majuscule$epithete) ($epithete) (var[.]) ($epithete)$/", $nomSci, $match)) {
$infos['genre'] = $match[1];
$infos['epithete_sp'] = $match[2];
$infos['type_epithete'] = $match[3];
$infos['epithete_infra_sp'] = $match[4];
} else {
$this->messages->traiterErreur("Le nom $nomSci ($id) de rang $rang n'est pas standard.");
}
}
 
$this->indexFinal[$nnc] = $infos;
$this->messages->afficherAvancement("Décomposition des noms scientifiques en cours");
}
echo "\n";
}
 
private function ajouteurNomSciHtml() {
foreach ($this->indexFinal as $nnc => $infos) {
$this->indexFinal[$nnc]['nom_sci_html'] = $this->generateur->genererNomSciHtml($infos);
$this->messages->afficherAvancement("Création des noms scientifiques HTML en cours");
}
echo "\n";
}
 
private function insererCorrections() {
$correctionsFichier = $this->dossierBase.self::DOSSIER_V2.'coste_v2_00_corrections.tsv';
$corrections = $this->outils->transformerTxtTsvEnTableau($correctionsFichier);
foreach ($corrections as $infos) {
$nnc = $infos['num_nom_coste'];
$infosACorriger = isset($this->indexFinal[$nnc]) ? $this->indexFinal[$nnc] : array();
foreach ($corrections as $champ => $valeur) {
$infosACorriger[$champ] = $valeur;
}
$this->indexFinal[$nnc] = $infosACorriger;
}
}
 
private function creerFichierCsvIndexFinal() {
$lignes = array();
array_unshift($this->indexFinal, $this->enteteFinal);
foreach ($this->indexFinal as $infos) {
$lignes[] = implode("\t", $infos);
}
 
$txt = '';
$txt = implode("\n", $lignes);
 
$fichierTsvIndexFinal = $this->dossierBase.self::DOSSIER_V2.'coste_v2_00.tsv';
file_put_contents($fichierTsvIndexFinal, $txt);
}
}
?>
/tags/v5.5-arbousiere/scripts/modules/coste/Versions.php
New file
0,0 → 1,71
<?php
class Versions {
 
private $conteneur = null;
private $eflore = null;
private $bdd = null;
 
public function __construct(Conteneur $conteneur) {
$this->conteneur = $conteneur;
$this->eflore = $conteneur->getEfloreCommun();
$this->bdd = $conteneur->getBdd();
}
 
public function chargerTous() {
$this->chargerVersions();
}
 
public function chargerVersions() {
$versions = explode(',', Config::get('versions'));
$versionsDonnees = explode(',', Config::get('versionsDonnees'));
foreach ($versions as $id => $version) {
$versionDonnees = $versionsDonnees[$id];
$this->chargerStructureSqlVersion($versionDonnees, $version);
$this->chargerIndexVersion($versionDonnees, $version);
$this->chargerDumpWikiniVersion($versionDonnees, $version);
}
}
 
private function chargerStructureSqlVersion($versionDonnees, $version) {
$fichierSqlTpl = Config::get('chemins.structureSqlVersionTpl');
$fichierSql = sprintf($fichierSqlTpl, $versionDonnees, $version);
$contenuSql = $this->eflore->recupererContenu($fichierSql);
$this->eflore->executerScriptSql($contenuSql);
}
 
private function chargerIndexVersion($versionDonnees, $version) {
$fichierTsvTpl = Config::get('chemins.costeTpl');
$fichierTsv = sprintf($fichierTsvTpl, $versionDonnees, $version);
$tableTpl = Config::get('tables.costeTpl');
$table = sprintf($tableTpl, $version);
$requete = "LOAD DATA INFILE '$fichierTsv' ".
"REPLACE INTO TABLE $table ".
'CHARACTER SET utf8 '.
'FIELDS '.
" TERMINATED BY '\t' ".
" ENCLOSED BY '' ".
" ESCAPED BY '\\\' ".
'IGNORE 1 LINES ';
$this->bdd->requeter($requete);
}
 
private function chargerDumpWikiniVersion($versionDonnees, $version) {
$versionMajeure = (int) substr($version, 0, 1);
if ($versionMajeure < 2) {
$fichierWikiTpl = Config::get('chemins.costeWikiniTpl');
$fichierDump = sprintf($fichierWikiTpl, $versionDonnees, $version);
$contenuSql = $this->eflore->recupererContenu($fichierDump);
$this->eflore->executerScriptSql($contenuSql);
}
}
 
public function supprimerTous() {
$requete = "DROP TABLE IF EXISTS coste_meta, ".
" coste_correspondance_bdnff, coste_images_auteur_correspondance_bdnff, ".
" coste_images_correspondance_bdnff, coste_index, coste_index_general, ".
" coste_acls, coste_links, coste_pages, coste_referrers, coste_triples, coste_users, ".
" coste_v1_00, coste_v2_00 ";
$this->bdd->requeter($requete);
}
}
?>