Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 130 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
123 jpm 1
<?php
2
//declare(encoding='UTF-8');
3
/**
4
 * Exemple de lancement du script : :
5
 * /opt/lampp/bin/php cli.php cel -a chargerTous
6
 *
7
 * @category	php 5.2
8
 * @package		eFlore/Scripts
9
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
 * @copyright	Copyright (c) 2011, Tela Botanica (accueil@tela-botanica.org)
11
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
12
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
13
 * @version		$Id$
14
 */
15
class Cel extends EfloreScript {
16
 
17
	public function executer() {
18
		try {
19
			$this->initialiserProjet('cel');
20
 
21
			// Lancement de l'action demandée
22
			$cmd = $this->getParametre('a');
23
			switch ($cmd) {
24
				case 'chargerTous' :
25
					$this->chargerStructureSql();
26
					$this->chargerCel();
27
					break;
28
				default :
29
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
30
			}
31
		} catch (Exception $e) {
32
			$this->traiterErreur($e->getMessage());
33
		}
34
	}
35
 
36
	public function chargerCel() {
37
		$tablesCodes = array_keys(Config::get('tables'));
38
		foreach ($tablesCodes as $code) {
39
			echo "Chargement de la table : $code\n";
40
			$this->chargerFichierTsvDansTable($code);
41
		}
42
	}
43
 
44
	private function chargerFichierTsvDansTable($code) {
45
		$chemin = Config::get('chemins.'.$code);
46
		$table = Config::get('tables.'.$code);
47
		$requete = "LOAD DATA INFILE '$chemin' ".
48
			"REPLACE INTO TABLE $table ".
49
			'CHARACTER SET utf8 '.
50
			'FIELDS '.
51
			"	TERMINATED BY '\t' ".
52
			"	ENCLOSED BY '' ".
53
			"	ESCAPED BY '\\\' ".
54
			'IGNORE 1 LINES';
55
		$this->getBdd()->requeter($requete);
56
	}
57
}
58
?>