Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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