Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 906 | Rev 1076 | Go to most recent revision | Details | Compare with Previous | 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;
906 delphine 33
				case 'supprimerOntologies' :
34
					$this->supprimerOntologies();
35
					break;
588 mathilde 36
				case 'chargerOntologies' :
37
					$this->chargerOntologies();
38
					break;
39
				case 'chargerTous' :
40
					$this->supprimerTous();
41
					$this->chargerStructureSql();
42
					$this->chargerMetadonnees();
43
					$this->chargerDonnees();
44
					$this->chargerOntologies();
45
					break;
46
				default :
47
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
48
			}
49
		} catch (Exception $e) {
50
			$this->traiterErreur($e->getMessage());
51
		}
52
	}
53
 
600 mathilde 54
 
55
	private function  getClasseBasevegVerif() {
56
		$conteneur = new Conteneur();
57
		require_once dirname(__FILE__)."/BasevegVerif.php";
58
		$verif = new BasevegVerif($conteneur,'baseveg');
59
		return $verif;
60
	}
61
 
62
	private function verifierFichier() {
63
		$verif = $this->getClasseBasevegVerif();
64
		$verif->verifierFichier(Config::get('chemins.donnees'));
65
	}
66
 
992 delphine 67
	private function supprimerOntologies() {
906 delphine 68
		$chemin = Config::get('chemins.ontologies');
69
		$table = Config::get('tables.ontologies');
70
		$requete = "TRUNCATE TABLE $table ;";
71
		$this->getBdd()->requeter($requete);
72
	}
600 mathilde 73
 
588 mathilde 74
	private function chargerOntologies() {
75
		$chemin = Config::get('chemins.ontologies');
76
		$table = Config::get('tables.ontologies');
906 delphine 77
		$requete = "LOAD DATA INFILE '$chemin' ".
588 mathilde 78
				"REPLACE INTO TABLE $table ".
79
				'CHARACTER SET utf8 '.
80
				'FIELDS '.
81
				"	TERMINATED BY '\t' ".
82
				"	ENCLOSED BY '' ".
83
				"	ESCAPED BY '\\\' "
84
		;
85
		$this->getBdd()->requeter($requete);
86
	}
87
 
88
	private function chargerDonnees() {
89
		$table = Config::get('tables.donnees');
90
		$requete = "LOAD DATA INFILE '".Config::get('chemins.donnees')."' ".
91
				"REPLACE INTO TABLE $table ".
92
				'CHARACTER SET utf8 '.
93
				'FIELDS '.
94
				"	TERMINATED BY '\t' ".
95
				"	ENCLOSED BY '' ".
96
				"	ESCAPED BY '\\\'";
97
		$this->getBdd()->requeter($requete);
98
	}
99
 
100
	protected function chargerMetadonnees() {
101
		$contenuSql = $this->recupererContenu(Config::get('chemins.metadonnees'));
102
		$this->executerScripSql($contenuSql);
103
	}
104
 
105
	private function supprimerTous() {
600 mathilde 106
		$requete = "DROP TABLE IF EXISTS  baseveg_meta,  baseveg_ontologies, baseveg_v".Config::get('version');
588 mathilde 107
		$this->getBdd()->requeter($requete);
108
	}
109
 
110
}
111
?>