Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 130 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
33 jpm 1
<?php
2
/** Exemple lancement:
42 jpm 3
 * /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php insee_d
33 jpm 4
 * 		-a chargerTous
5
 * Options :
6
 * -t : Permet de tester le script sur un jeux réduit de données (indiquer le nombre de lignes).
7
*/
75 jpm 8
class InseeD extends EfloreScript {
33 jpm 9
 
10
	public function executer() {
11
		// Lancement de l'action demandée
12
		try {
75 jpm 13
			$this->initialiserProjet('insee-d');
33 jpm 14
 
15
			$cmd = $this->getParametre('a');
16
		    switch ($cmd) {
17
		    	case 'chargerTous' :
18
		    		$this->chargerStructureSql();
19
		    		$this->chargerInseeD();
20
		    		$this->chargerOntologies();
21
		    		break;
22
	    		case 'chargerStructureSql' :
23
	    			$this->chargerStructureSql();
24
	    			break;
25
				case 'chargerInseeD' :
26
					$this->chargerInseeD();
27
					break;
28
				case 'chargerOntologies' :
29
					$this->chargerOntologies();
30
					break;
130 jpm 31
				case 'supprimerTous' :
32
					$this->supprimerTous();
33
					break;
33 jpm 34
				default :
75 jpm 35
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
33 jpm 36
			}
37
		} catch (Exception $e) {
38
			$this->traiterErreur($e->getMessage());
39
		}
40
    }
41
 
42
	private function chargerInseeD() {
43
		$chemin = Config::get('chemins.inseeD');
44
		$table = Config::get('tables.inseeD');
45
		$requete = "LOAD DATA INFILE '$chemin' ".
46
			"REPLACE INTO TABLE $table ".
47
			'CHARACTER SET utf8 '.
48
			'FIELDS '.
49
			"	TERMINATED BY ';' ".
50
			"	ENCLOSED BY '\"' ".
51
			"	ESCAPED BY '\\\' ".
52
			'IGNORE 0 LINES';
75 jpm 53
		$this->getBdd()->requeter($requete);
33 jpm 54
	}
55
 
56
	private function chargerOntologies() {
57
		$chemin = Config::get('chemins.ontologies');
58
		$table = Config::get('tables.ontologies');
59
		$requete = "LOAD DATA INFILE '$chemin' ".
60
			"REPLACE INTO TABLE $table ".
61
			'CHARACTER SET utf8 '.
62
			'FIELDS '.
63
			"	TERMINATED BY '\t' ".
64
			"	ENCLOSED BY '' ".
65
			"	ESCAPED BY '\\\' ".
66
			'IGNORE 1 LINES';
75 jpm 67
		$this->getBdd()->requeter($requete);
33 jpm 68
	}
130 jpm 69
 
70
	private function supprimerTous() {
351 jpm 71
		$requete = "DROP TABLE IF EXISTS insee_d_meta, insee_d_ontologies_v2011, insee_d_v2011";
130 jpm 72
		$this->getBdd()->requeter($requete);
73
	}
33 jpm 74
}
75
?>