Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 424 | Rev 469 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?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' :
                                        $this->chargerStructureSql();
                                        $this->chargerVersions();
                                        break;
                                case 'chargerStructureSql' :
                                        $this->chargerStructureSql();
                                        break;
                                case 'chargerVersions' :
                                        $this->chargerVersions();
                                        break;
                                case 'supprimerTous' :
                                        $this->supprimerTous();
                                        break;
                                case 'creerV1' :
                                        $this->creerVersion1();
                                        break;
                                case 'nettoyerV1' :
                                        $this->nettoyerVersion1();
                                        break;
                                case 'creerDscTxt' :
                                        $this->creerDescriptionTxt();
                                        break;
                                case 'statDscTxt' :
                                        $this->verifierDescriptionTxt();
                                        break;
                                case 'correspondanceDsc' :
                                        $this->genererCorrespondanceDescription();
                                        break;
                                default :
                                        throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
                        }
                } catch (Exception $e) {
                        $this->traiterErreur($e->getMessage());
                }
        }

        private 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->recupererContenu($fichierSql);
                $this->executerScripSql($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->getBdd()->requeter($requete);
        }

        private function chargerDumpWikiniVersion($versionDonnees, $version) {
                $fichierWikiTpl = Config::get('chemins.costeWikiniTpl');
                $fichierDump = sprintf($fichierWikiTpl, $versionDonnees, $version);
                $contenuSql = $this->recupererContenu($fichierDump);
                $this->executerScripSql($contenuSql);
        }

        private function supprimerTous() {
                $requete = "DROP TABLE IF EXISTS coste_meta, ".
                        "       coste_acls, coste_links, coste_pages, coste_referrers, coste_triples, coste_users, ".
                        "       coste_v1_00 ";
                $this->getBdd()->requeter($requete);
        }

        private function nettoyerVersion1() {
                $requete = "DROP TABLE IF EXISTS coste_correspondance_bdnff, coste_images_auteur_correspondance_bdnff, ".
                        "       coste_images_correspondance_bdnff, coste_index, coste_index_general";
                $this->getBdd()->requeter($requete);
        }

        private function creerVersion1() {
                $this->chargerStructureSqlVersion('0.00', '0_00');
                $this->chargerCosteImagesAuteurCorrespondanceBdnff();
                $this->chargerCosteCorrespondanceBdnff();
        }

        private function chargerCosteImagesAuteurCorrespondanceBdnff() {
                $fichierTsv = sprintf(Config::get('dossierTsvTpl'), '0.00').'coste_images_auteur_correspondance_bdnff.tsv';
                $requete = "LOAD DATA INFILE '$fichierTsv' ".
                                "REPLACE INTO TABLE coste_images_auteur_correspondance_bdnff ".
                                'CHARACTER SET utf8 '.
                                'FIELDS '.
                                "       TERMINATED BY '\t' ".
                                "       ENCLOSED BY '\"' ".
                                "       ESCAPED BY '\\\' ".
                                'IGNORE 1 LINES ';
                $this->getBdd()->requeter($requete);
        }

        private function chargerCosteCorrespondanceBdnff() {
                $fichierTsv = sprintf(Config::get('dossierTsvTpl'), '0.00').'coste_images_correspondance_bdnff.tsv';
                $requete = "LOAD DATA INFILE '$fichierTsv' ".
                                        "REPLACE INTO TABLE coste_images_correspondance_bdnff ".
                                        'CHARACTER SET utf8 '.
                                        'FIELDS '.
                                        "       TERMINATED BY '\t' ".
                                        "       ENCLOSED BY '' ".
                                        "       ESCAPED BY '\\\' ".
                                        'IGNORE 1 LINES ';
                $this->getBdd()->requeter($requete);
        }

        private function creerDescriptionTxt() {
                $description = $this->getClasseDescription();
                $description->genererDescriptionTxt();
        }

        private function verifierDescriptionTxt() {
                $description = $this->getClasseDescription();
                $description->verifierDescriptionTxt();
        }

        private function genererCorrespondanceDescription() {
                $description = $this->getClasseDescription();
                $description->genererCorrespondance();
        }

        private function  getClasseDescription() {
                $conteneur = new Conteneur();
                $conteneur->setParametre('-v', $this->getParametre('-v'));
                require_once dirname(__FILE__)."/Description.php";
                $description = new Description($conteneur);
                return $description;
        }
}
?>