Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 122 | 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() {
122 jpm 48
		$fichierIni = $this->getScriptChemin().$this->getProjetNom().'.ini';
49
		if (file_exists($fichierIni)) {
50
			Config::charger($fichierIni);
51
		} else {
52
			$m = "Veuillez configurer le projet en créant le fichier '{$this->projetNom}.ini' ".
53
				"dans le dossier du module de script du projet à partir du fichier '{$this->projetNom}.defaut.ini'.";
54
			throw new Exception($m);
66 jpm 55
		}
56
	}
57
 
58
	protected function chargerStructureSql() {
59
		$contenuSql = $this->recupererContenu(Config::get('chemins.structureSql'));
103 jpm 60
		$this->executerScripSql($contenuSql);
61
	}
62
 
63
	protected function executerScripSql($sql) {
64
		$requetes = Outils::extraireRequetes($sql);
66 jpm 65
		foreach ($requetes as $requete) {
66
			$this->getBdd()->requeter($requete);
67
		}
68
	}
69
 
67 jpm 70
	protected function recupererContenu($chemin) {
71
		$contenu = file_get_contents($chemin);
72
		if ($contenu === false){
73
			throw new Exception("Impossible d'ouvrir le fichier SQL : $chemin");
74
		}
75
		return $contenu;
76
	}
77
 
107 jpm 78
	protected function stopperLaBoucle($limite = false) {
66 jpm 79
		$stop = false;
107 jpm 80
		if ($limite) {
81
			static $ligneActuelle = 1;
82
			if ($limite == $ligneActuelle++) {
83
				$stop = true;
84
			}
66 jpm 85
		}
86
		return $stop;
87
	}
88
}
89
?>