Subversion Repositories eFlore/Projets.eflore-projets

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
577 delphine 1
<?php
2
/** Exemple lancement:
3
 * /opt/lampp/bin/php -d memory_limit=3500M cli.php sptb -a chargerTous
4
*/
5
class Sptb extends EfloreScript {
6
 
7
	public function executer() {
8
		// Lancement de l'action demandée
9
		try {
10
			$this->initialiserProjet('sptb');
11
 
12
			$cmd = $this->getParametre('a');
13
		    switch ($cmd) {
14
		    	case 'chargerTous' :
15
		    		$this->chargerStructureSql();
16
		    		$this->chargerDonnees('especes');
17
		    		$this->chargerDonnees('lois');
18
		    		break;
19
	    		case 'chargerStructureSql' :
20
	    			$this->chargerStructureSql();
21
	    			break;
22
				case 'chargerDonnees' :
23
		    		$this->chargerDonnees('especes');
24
		    		$this->chargerDonnees('lois');
25
					break;
26
				case 'supprimerTous' :
27
					$this->supprimerTous();
28
					break;
29
				default :
30
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
31
			}
32
		} catch (Exception $e) {
33
			$this->traiterErreur($e->getMessage());
34
		}
35
    }
36
 
37
	private function chargerDonnees($type) {
38
		$chemin = Config::get('chemins.'.$type);
39
		$table = Config::get('tables.'.$type);
40
		$requete = "LOAD DATA INFILE '$chemin' ".
41
			"REPLACE INTO TABLE $table ".
42
			'CHARACTER SET utf8 '.
43
			'FIELDS '.
44
			"	TERMINATED BY '\t' ".
45
			"	ENCLOSED BY '' ".
46
			"	ESCAPED BY '\\\' ".
47
			'IGNORE 1 LINES';
48
		$this->getBdd()->requeter($requete);
49
	}
50
 
51
	private function supprimerTous() {
52
		$requete = "DROP TABLE IF EXISTS sptb_meta, sptb_especes_v2012, sptb_lois_v2012";
53
		$this->getBdd()->requeter($requete);
54
		Debug::printr('suppression');
55
	}
56
}
57
?>