Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 577 | Rev 1186 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 577 Rev 639
1
<?php
1
<?php
2
/** Exemple lancement:
2
/** Exemple lancement:
3
 * /opt/lampp/bin/php -d memory_limit=3500M cli.php sptb -a chargerTous
3
 * /opt/lampp/bin/php -d memory_limit=3500M cli.php sptb -a chargerTous
4
*/
4
*/
5
class Sptb extends EfloreScript {
5
class Sptb extends EfloreScript {
6
 
6
 
7
	public function executer() {
7
	public function executer() {
8
		// Lancement de l'action demandée
8
		// Lancement de l'action demandée
9
		try {
9
		try {
10
			$this->initialiserProjet('sptb');
10
			$this->initialiserProjet('sptb');
11
 
11
 
12
			$cmd = $this->getParametre('a');
12
			$cmd = $this->getParametre('a');
13
		    switch ($cmd) {
13
		    switch ($cmd) {
14
		    	case 'chargerTous' :
14
		    	case 'chargerTous' :
15
		    		$this->chargerStructureSql();
15
		    		$this->chargerStructureSql();
16
		    		$this->chargerDonnees('especes');
16
		    		$this->chargerDonnees('especes');
17
		    		$this->chargerDonnees('lois');
17
		    		$this->chargerDonnees('lois');
-
 
18
		    		$this->genererChampNumNomRetenu();
18
		    		break;
19
		    		break;
19
	    		case 'chargerStructureSql' :
20
	    		case 'chargerStructureSql' :
20
	    			$this->chargerStructureSql();
21
	    			$this->chargerStructureSql();
21
	    			break;
22
	    			break;
22
				case 'chargerDonnees' :
23
				case 'chargerDonnees' :
23
		    		$this->chargerDonnees('especes');
24
		    		$this->chargerDonnees('especes');
24
		    		$this->chargerDonnees('lois');
25
		    		$this->chargerDonnees('lois');
-
 
26
		    		$this->genererChampNumNomRetenu();
-
 
27
					break;
-
 
28
				case 'genererChampNumNomRetenu' :
-
 
29
					$this->genererChampNumNomRetenu();
25
					break;
30
					break;
26
				case 'supprimerTous' :
31
				case 'supprimerTous' :
27
					$this->supprimerTous();
32
					$this->supprimerTous();
28
					break;
33
					break;
29
				default :
34
				default :
30
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
35
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
31
			}
36
			}
32
		} catch (Exception $e) {
37
		} catch (Exception $e) {
33
			$this->traiterErreur($e->getMessage());
38
			$this->traiterErreur($e->getMessage());
34
		}
39
		}
35
    }
40
    }
36
 
41
 
37
	private function chargerDonnees($type) {
42
	private function chargerDonnees($type) {
38
		$chemin = Config::get('chemins.'.$type);
43
		$chemin = Config::get('chemins.'.$type);
39
		$table = Config::get('tables.'.$type);
44
		$table = Config::get('tables.'.$type);
40
		$requete = "LOAD DATA INFILE '$chemin' ".
45
		$requete = "LOAD DATA INFILE '$chemin' ".
41
			"REPLACE INTO TABLE $table ".
46
			"REPLACE INTO TABLE $table ".
42
			'CHARACTER SET utf8 '.
47
			'CHARACTER SET utf8 '.
43
			'FIELDS '.
48
			'FIELDS '.
44
			"	TERMINATED BY '\t' ".
49
			"	TERMINATED BY '\t' ".
45
			"	ENCLOSED BY '' ".
50
			"	ENCLOSED BY '' ".
46
			"	ESCAPED BY '\\\' ".
51
			"	ESCAPED BY '\\\' ".
47
			'IGNORE 1 LINES';
52
			'IGNORE 1 LINES';
48
		$this->getBdd()->requeter($requete);
53
		$this->getBdd()->requeter($requete);
-
 
54
	}
-
 
55
	
-
 
56
	private function genererChampNumNomRetenu() {
-
 
57
		$this->preparerTablePrChpNumNomRetenu();
-
 
58
		$this->genererNumNomRetenu();
-
 
59
	}
-
 
60
	
-
 
61
	private function preparerTablePrChpNumNomRetenu() {
-
 
62
		$table = Config::get('tables.especes');
-
 
63
		$requete = "SHOW COLUMNS FROM $table LIKE 'num_nom_retenu' ";
-
 
64
		$resultat = $this->getBdd()->recuperer($requete);
-
 
65
		if ($resultat === false) {
-
 
66
			$requete = 	"ALTER TABLE $table ".
-
 
67
					'ADD num_nom_retenu INT(10) '.
-
 
68
					'NULL DEFAULT NULL AFTER num_nom';
-
 
69
			$this->getBdd()->requeter($requete);
-
 
70
		}
-
 
71
	}
-
 
72
	
-
 
73
	private function genererNumNomRetenu() {
-
 
74
		$table = Config::get('tables.especes');
-
 
75
		$table_referentiel = Config::get('tables.referentielTaxo');
-
 
76
		
-
 
77
		$requete = 'UPDATE '.$table.' s, '.$table_referentiel.' r '.
-
 
78
		           'SET s.num_nom_retenu = r.num_nom_retenu '.
-
 
79
		           '	WHERE s.num_nom = r.num_nom ';
-
 
80
		
-
 
81
		$this->getBdd()->requeter($requete);
49
	}
82
	}
50
 
83
 
51
	private function supprimerTous() {
84
	private function supprimerTous() {
52
		$requete = "DROP TABLE IF EXISTS sptb_meta, sptb_especes_v2012, sptb_lois_v2012";
85
		$requete = "DROP TABLE IF EXISTS sptb_meta, sptb_especes_v2012, sptb_lois_v2012";
53
		$this->getBdd()->requeter($requete);
86
		$this->getBdd()->requeter($requete);
54
		Debug::printr('suppression');
87
		Debug::printr('suppression');
55
	}
88
	}
56
}
89
}
57
?>
90
?>