Subversion Repositories eFlore/Projets.eflore-projets

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
588 mathilde 1
<?php
2
/** Exemple lancement:
3
 * /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php baseveg -a chargerTous
4
*/
5
 
6
class Baseveg extends EfloreScript {
7
 
600 mathilde 8
 
9
 
10
 
588 mathilde 11
 
12
	public function executer() {
13
		try {
14
			$this->initialiserProjet('baseveg');
15
			$cmd = $this->getParametre('a');
16
			switch ($cmd) {
17
				case 'supprimerTous' :
18
					$this->supprimerTous();
19
					break;
20
				case 'chargerStructureSql' :
21
					$this->chargerStructureSql();
22
					break;
23
				case 'chargerMetadonnees' :
24
					$this->chargerMetadonnees();
25
					break;
26
				case 'chargerDonnees' :
27
					$this->chargerDonnees();
28
					break;
29
				case 'verifierFichier' :
30
					//cette étape met en avant les valeurs qui vont poser des problèmes (ontologies..)
31
					$this->verifierFichier();
32
					break;
33
				case 'chargerOntologies' :
34
					$this->chargerOntologies();
35
					break;
36
				case 'chargerTous' :
37
					$this->supprimerTous();
38
					$this->chargerStructureSql();
39
					$this->chargerMetadonnees();
40
					$this->chargerDonnees();
41
					$this->chargerOntologies();
42
					break;
43
				default :
44
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
45
			}
46
		} catch (Exception $e) {
47
			$this->traiterErreur($e->getMessage());
48
		}
49
	}
50
 
600 mathilde 51
 
52
	private function  getClasseBasevegVerif() {
53
		$conteneur = new Conteneur();
54
		require_once dirname(__FILE__)."/BasevegVerif.php";
55
		$verif = new BasevegVerif($conteneur,'baseveg');
56
		return $verif;
57
	}
58
 
59
	private function verifierFichier() {
60
		$verif = $this->getClasseBasevegVerif();
61
		$verif->verifierFichier(Config::get('chemins.donnees'));
62
	}
63
 
64
 
588 mathilde 65
	private function chargerOntologies() {
66
		$chemin = Config::get('chemins.ontologies');
67
		$table = Config::get('tables.ontologies');
68
		$requete = "TRUNCATE TABLE $table ;
69
		         LOAD DATA INFILE '$chemin' ".
70
				"REPLACE INTO TABLE $table ".
71
				'CHARACTER SET utf8 '.
72
				'FIELDS '.
73
				"	TERMINATED BY '\t' ".
74
				"	ENCLOSED BY '' ".
75
				"	ESCAPED BY '\\\' "
76
		;
77
		$this->getBdd()->requeter($requete);
78
	}
79
 
80
	private function chargerDonnees() {
81
		$table = Config::get('tables.donnees');
82
		$requete = "LOAD DATA INFILE '".Config::get('chemins.donnees')."' ".
83
				"REPLACE INTO TABLE $table ".
84
				'CHARACTER SET utf8 '.
85
				'FIELDS '.
86
				"	TERMINATED BY '\t' ".
87
				"	ENCLOSED BY '' ".
88
				"	ESCAPED BY '\\\'";
89
		$this->getBdd()->requeter($requete);
90
	}
91
 
92
	protected function chargerMetadonnees() {
93
		$contenuSql = $this->recupererContenu(Config::get('chemins.metadonnees'));
94
		$this->executerScripSql($contenuSql);
95
	}
96
 
97
	private function supprimerTous() {
600 mathilde 98
		$requete = "DROP TABLE IF EXISTS  baseveg_meta,  baseveg_ontologies, baseveg_v".Config::get('version');
588 mathilde 99
		$this->getBdd()->requeter($requete);
100
	}
101
 
102
}
103
?>