Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 683 | Blame | Last modification | View Log | RSS feed

<?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->chargerStructureSql();
                $this->chargerVersions();
        }

        public function chargerStructureSql() {
                $this->eflore->chargerStructureSql();
        }

        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) {
                $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);
        }
}
?>