Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

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