Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 300 Rev 349
1
<?php
1
<?php
2
//declare(encoding='UTF-8');
2
//declare(encoding='UTF-8');
3
/**
3
/**
4
 * Exemple de lancement du script : :
4
 * Exemple de lancement du script : :
5
 * /opt/lampp/bin/php cli.php cel -a chargerTous
5
 * /opt/lampp/bin/php cli.php cel -a chargerTous
6
 *
6
 *
7
 * @category	php 5.2
7
 * @category	php 5.2
8
 * @package		eFlore/Scripts
8
 * @package		eFlore/Scripts
9
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
 * @copyright	Copyright (c) 2011, Tela Botanica (accueil@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
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
12
 * @license		http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
13
 * @version		$Id$
13
 * @version		$Id$
14
 */
14
 */
15
class BiblioBota extends EfloreScript {
15
class BiblioBota extends EfloreScript {
16
 
16
 
17
	public function executer() {
17
	public function executer() {
18
		try {
18
		try {
19
			$this->initialiserProjet('biblio_bota');
19
			$this->initialiserProjet('biblio_bota');
20
 
20
 
21
			// Lancement de l'action demandée
21
			// Lancement de l'action demandée
22
			$cmd = $this->getParametre('a');
22
			$cmd = $this->getParametre('a');
23
			switch ($cmd) {
23
			switch ($cmd) {
24
				case 'chargerTous' :
24
				case 'chargerTous' :
25
					$this->chargerStructureSql();
25
					$this->chargerStructureSql();
26
					$this->chargerBiblioBota();
26
					$this->chargerBiblioBota();
27
					break;
27
					break;
28
				case 'supprimerTous' :
28
				case 'supprimerTous' :
29
					$this->supprimerTous();
29
					$this->supprimerTous();
30
					break;
30
					break;
31
				default :
31
				default :
32
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
32
					throw new Exception("Erreur : la commande '$cmd' n'existe pas!");
33
			}
33
			}
34
		} catch (Exception $e) {
34
		} catch (Exception $e) {
35
			$this->traiterErreur($e->getMessage());
35
			$this->traiterErreur($e->getMessage());
36
		}
36
		}
37
	}
37
	}
38
 
38
 
39
	public function chargerBiblioBota() {
39
	public function chargerBiblioBota() {
40
		$tablesCodes = array_keys(Config::get('tables'));
40
		$tablesCodes = array_keys(Config::get('tables'));
41
		foreach ($tablesCodes as $code) {
41
		foreach ($tablesCodes as $code) {
42
			echo "Chargement de la table : $code\n";
42
			echo "Chargement de la table : $code\n";
43
			$this->chargerFichierTsvDansTable($code);
43
			$this->chargerFichierTsvDansTable($code);
44
		}
44
		}
45
	}
45
	}
46
 
46
 
47
	private function chargerFichierTsvDansTable($code) {
47
	private function chargerFichierTsvDansTable($code) {
48
		$chemin = Config::get('chemins.'.$code);
48
		$chemin = Config::get('chemins.'.$code);
49
		$table = Config::get('tables.'.$code);
49
		$table = Config::get('tables.'.$code);
50
		$requete = "LOAD DATA INFILE '$chemin' ".
50
		$requete = "LOAD DATA INFILE '$chemin' ".
51
			"REPLACE INTO TABLE $table ".
51
			"REPLACE INTO TABLE $table ".
52
			'CHARACTER SET utf8 '.
52
			'CHARACTER SET utf8 '.
53
			'FIELDS '.
53
			'FIELDS '.
54
			"	TERMINATED BY '\t' ".
54
			"	TERMINATED BY '\t' ".
55
			"	ENCLOSED BY '\"' ".
55
			"	ENCLOSED BY '\"' ".
56
			"	ESCAPED BY '\\\' ";
56
			"	ESCAPED BY '\\\' ";
57
		$this->getBdd()->requeter($requete);
57
		$this->getBdd()->requeter($requete);
58
	}
58
	}
59
 
59
 
60
	private function supprimerTous() {
60
	private function supprimerTous() {
61
		$requete = "DROP TABLE `biblio_article`, `biblio_article_sauv`, `biblio_aut_saisie`, `biblio_collection`, `biblio_domaine`, `biblio_domaine_lier`, `biblio_domaine_lier_sauv`, `biblio_fasc`, `biblio_fasc_sauv`, `biblio_item`, `biblio_item_sauv`, `biblio_item_typlog`, `biblio_item_typphy`, `biblio_link`, `biblio_link_categ`, `biblio_link_categoriser`, `biblio_link_sauv`, `biblio_media`, `biblio_modif`, `biblio_serie`, `biblio_spy`, `biblio_str`, `biblio_str_sauve`, `biblio_str_type`";
61
		$requete = "DROP TABLE IF EXISTS biblio_article, biblio_article_sauv, biblio_aut_saisie, ".
-
 
62
			"biblio_collection, biblio_domaine, biblio_domaine_lier, biblio_domaine_lier_sauv, biblio_fasc, ".
-
 
63
			"biblio_fasc_sauv, biblio_item, biblio_item_sauv, biblio_item_typlog, biblio_item_typphy, ".
-
 
64
			"biblio_link, biblio_link_categ, biblio_link_categoriser, biblio_link_sauv, biblio_media, ".
-
 
65
			"biblio_modif, biblio_serie, biblio_spy, biblio_str, biblio_str_sauve, biblio_str_type ";
62
		$this->getBdd()->requeter($requete);
66
		$this->getBdd()->requeter($requete);
63
	}
67
	}
64
}
68
}
65
?>
69
?>