Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 130 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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