Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

<?php
/** Exemple lancement:
 * /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php baseveg -a chargerTous
*/

class Baseveg extends EfloreScript {




        
        public function executer() {
                try {
                        $this->initialiserProjet('baseveg');
                        $cmd = $this->getParametre('a');
                        switch ($cmd) {
                                case 'supprimerTous' :
                                        $this->supprimerTous();
                                        break;
                                case 'chargerStructureSql' :
                                        $this->chargerStructureSql();
                                        break;
                                case 'chargerMetadonnees' :
                                        $this->chargerMetadonnees();
                                        break;
                                case 'chargerDonnees' :
                                        $this->chargerDonnees();
                                        break;
                                case 'verifierFichier' :
                                        //cette étape met en avant les valeurs qui vont poser des problèmes (ontologies..)
                                        $this->verifierFichier();
                                        break;
                                case 'supprimerOntologies' :
                                        $this->supprimerOntologies();
                                        break;
                                case 'chargerOntologies' :
                                        $this->chargerOntologies();
                                        break;
                                case 'chargerTous' :
                                        $this->supprimerTous();
                                        $this->chargerStructureSql();
                                        $this->chargerMetadonnees();
                                        $this->chargerDonnees();
                                        $this->chargerOntologies();
                                        break;
                                default :
                                        throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
                        }
                } catch (Exception $e) {
                        $this->traiterErreur($e->getMessage());
                }
        }
        
        
        private function  getClasseBasevegVerif() {
                $conteneur = new Conteneur();
                require_once dirname(__FILE__)."/BasevegVerif.php";
                $verif = new BasevegVerif($conteneur,'baseveg');
                return $verif;
        }
        
        private function verifierFichier() {
                $verif = $this->getClasseBasevegVerif();
                $verif->verifierFichier(Config::get('chemins.donnees'));
        }
        
        private function supprimerOntologies() {
                $chemin = Config::get('chemins.ontologies');
                $table = Config::get('tables.ontologies');
                $requete = "TRUNCATE TABLE $table ;";
                $this->getBdd()->requeter($requete);
        }
        
        private function chargerOntologies() {
                $chemin = Config::get('chemins.ontologies');
                $table = Config::get('tables.ontologies');
                $requete = "LOAD DATA INFILE '$chemin' ".
                                "REPLACE INTO TABLE $table ".
                                'CHARACTER SET utf8 '.
                                'FIELDS '.
                                "       TERMINATED BY '\t' ".
                                "       ENCLOSED BY '' ".
                                "       ESCAPED BY '\\\' "
                ;
                $this->getBdd()->requeter($requete);
        }

        private function chargerDonnees() {
                $table = Config::get('tables.donnees');
                $requete = "LOAD DATA INFILE '".Config::get('chemins.donnees')."' ".
                                "REPLACE INTO TABLE $table ".
                                'CHARACTER SET utf8 '.
                                'FIELDS '.
                                "       TERMINATED BY '\t' ".
                                "       ENCLOSED BY '' ".
                                "       ESCAPED BY '\\\'";
                $this->getBdd()->requeter($requete);
        }
        
        protected function chargerMetadonnees() {
                $contenuSql = $this->recupererContenu(Config::get('chemins.metadonnees'));
                $this->executerScripSql($contenuSql);
        }

        private function supprimerTous() {
                $requete = "DROP TABLE IF EXISTS  baseveg_meta,  baseveg_ontologies, baseveg_v".Config::get('version');
                $this->getBdd()->requeter($requete);
        }

}
?>