Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev Author Line No. Line
70 jpm 1
<?php
2
/** Exemple lancement:
3
 * /opt/lampp/bin/php -d memory_limit=3500M ~/web/eflore-projets/scripts/cli.php iso6391
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
*/
8
class Iso31661 extends EfloreScript {
9
 
10
	public function executer() {
11
		// Lancement de l'action demandée
12
		try {
13
			$this->initialiserProjet('iso-3166-1');
14
 
15
			$cmd = $this->getParametre('a');
16
		    switch ($cmd) {
17
		    	case 'chargerTous' :
18
		    		$this->chargerStructureSql();
19
		    		$this->chargerIso31661();
20
		    		$this->chargerOntologies();
21
		    		break;
22
	    		case 'chargerStructureSql' :
23
	    			$this->chargerStructureSql();
24
	    			break;
25
				case 'chargerIso31661' :
26
					$this->chargerIso31661();
27
					break;
28
				case 'chargerOntologies' :
29
					$this->chargerOntologies();
30
					break;
31
				case 'test' :
32
					$this->tester();
33
					break;
130 jpm 34
				case 'supprimerTous' :
35
					$this->supprimerTous();
36
					break;
70 jpm 37
				default :
38
					$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
39
			}
40
		} catch (Exception $e) {
41
			$this->traiterErreur($e->getMessage());
42
		}
43
    }
44
 
45
    private function tester() {
46
    	echo Config::get('test');
47
    }
48
 
49
	private function chargerIso31661() {
50
		$chemin = Config::get('chemins.iso31661');
51
		$table = Config::get('tables.iso31661');
52
		$requete = "LOAD DATA INFILE '$chemin' ".
53
			"REPLACE INTO TABLE $table ".
54
			'CHARACTER SET utf8 '.
55
			'FIELDS '.
56
			"	TERMINATED BY '\t' ".
57
			"	ENCLOSED BY '\"' ".
58
			"	ESCAPED BY '\\\' ".
59
			'IGNORE 1 LINES';
60
		$this->getBdd()->requeter($requete);
61
	}
62
 
63
	private function chargerOntologies() {
64
		$chemin = Config::get('chemins.ontologies');
65
		$table = Config::get('tables.ontologies');
66
		$requete = "LOAD DATA INFILE '$chemin' ".
67
				"REPLACE INTO TABLE $table ".
68
				'CHARACTER SET utf8 '.
69
				'FIELDS '.
70
				"	TERMINATED BY '\t' ".
71
				"	ENCLOSED BY '\"' ".
72
				"	ESCAPED BY '\\\' ".
73
				'IGNORE 1 LINES';
74
		$this->getBdd()->requeter($requete);
75
	}
130 jpm 76
 
77
	private function supprimerTous() {
349 jpm 78
		$requete = "DROP TABLE IF EXISTS iso_3166_1_meta, iso_3166_1_ontologies_v2006, iso_3166_1_v2006";
130 jpm 79
		$this->getBdd()->requeter($requete);
80
	}
70 jpm 81
}
82
?>