Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 80 | Rev 107 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
66 jpm 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
 * EfloreScript est une classe abstraite qui doit être implémenté par les classes éxecutant des scripts
5
 * en ligne de commande pour les projets d'eFlore.
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.gnu.org/licenses/gpl.html Licence GNU-GPL-v3
12
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
13
 * @since 		0.3
14
 * @version		$Id$
15
 * @link		/doc/framework/
16
 */
17
abstract class EfloreScript extends Script {
18
 
19
	private $Bdd = null;
20
	private $projetNom = null;
21
 
22
	public function getProjetNom() {
23
		return $this->projetNom;
24
	}
25
 
26
	protected function initialiserProjet($projetNom) {
27
		$this->projetNom = $projetNom;
28
		$this->chargerConfigDuProjet();
29
	}
30
 
31
	//+------------------------------------------------------------------------------------------------------+
32
	// Méthodes d'accès aux objets du Framework
33
	/**
34
	* Méthode de connection à la base de données sur demande.
35
	* Tous les scripts n'ont pas besoin de s'y connecter.
36
	*/
37
	protected function getBdd() {
38
		if (! isset($this->Bdd)) {
39
			$this->Bdd = new Bdd();
40
		}
41
		return $this->Bdd;
42
	}
43
 
44
	//+------------------------------------------------------------------------------------------------------+
45
	// Méthodes communes aux projets d'eFlore
46
 
47
	protected function chargerConfigDuProjet() {
48
		$fichierIniDefaut = $this->getScriptChemin().$this->getProjetNom().'.defaut.ini';
49
		if (file_exists($fichierIniDefaut)) {
50
			$fichierIni = $this->getScriptChemin().$this->getProjetNom().'.ini';
51
			if (file_exists($fichierIni)) {
52
				Config::charger($fichierIni);
53
			} else {
54
				$m = "Veuillez configurer le projet en créant le fichier '{$this->projetNom}.ini' ".
55
					"dans le dossier du module de script du projet à partir du fichier '{$this->projetNom}.defaut.ini'.";
56
				throw new Exception($m);
57
			}
58
		}
59
	}
60
 
61
	protected function chargerStructureSql() {
62
		$contenuSql = $this->recupererContenu(Config::get('chemins.structureSql'));
103 jpm 63
		$this->executerScripSql($contenuSql);
64
	}
65
 
66
	protected function executerScripSql($sql) {
67
		$requetes = Outils::extraireRequetes($sql);
66 jpm 68
		foreach ($requetes as $requete) {
69
			$this->getBdd()->requeter($requete);
70
		}
71
	}
72
 
67 jpm 73
	protected function recupererContenu($chemin) {
74
		$contenu = file_get_contents($chemin);
75
		if ($contenu === false){
76
			throw new Exception("Impossible d'ouvrir le fichier SQL : $chemin");
77
		}
78
		return $contenu;
79
	}
80
 
66 jpm 81
	protected function stopperLaBoucle($limite) {
82
		$stop = false;
83
		static $ligneActuelle = 1;
80 jpm 84
		if ($limite == $ligneActuelle++) {
85
			$stop = true;
66 jpm 86
		}
87
		return $stop;
88
	}
89
}
90
?>