Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 48 | Rev 130 | Go to most recent revision | 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;
31
				default :
75 jpm 32
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
33 jpm 33
			}
34
		} catch (Exception $e) {
35
			$this->traiterErreur($e->getMessage());
36
		}
37
    }
38
 
39
	private function chargerInseeD() {
40
		$chemin = Config::get('chemins.inseeD');
41
		$table = Config::get('tables.inseeD');
42
		$requete = "LOAD DATA INFILE '$chemin' ".
43
			"REPLACE INTO TABLE $table ".
44
			'CHARACTER SET utf8 '.
45
			'FIELDS '.
46
			"	TERMINATED BY ';' ".
47
			"	ENCLOSED BY '\"' ".
48
			"	ESCAPED BY '\\\' ".
49
			'IGNORE 0 LINES';
75 jpm 50
		$this->getBdd()->requeter($requete);
33 jpm 51
	}
52
 
53
	private function chargerOntologies() {
54
		$chemin = Config::get('chemins.ontologies');
55
		$table = Config::get('tables.ontologies');
56
		$requete = "LOAD DATA INFILE '$chemin' ".
57
			"REPLACE INTO TABLE $table ".
58
			'CHARACTER SET utf8 '.
59
			'FIELDS '.
60
			"	TERMINATED BY '\t' ".
61
			"	ENCLOSED BY '' ".
62
			"	ESCAPED BY '\\\' ".
63
			'IGNORE 1 LINES';
75 jpm 64
		$this->getBdd()->requeter($requete);
33 jpm 65
	}
66
}
67
?>