Subversion Repositories Applications.referentiel

Rev

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

Rev 54 Rev 55
1
<?php
1
<?php
2
// Encodage : UTF-8
2
// Encodage : UTF-8
3
// +-------------------------------------------------------------------------------------------------------------------+
3
// +-------------------------------------------------------------------------------------------------------------------+
4
/**
4
/**
5
* Versionnage de référentiels de nomenclature et taxonomie
5
* Versionnage de référentiels de nomenclature et taxonomie
6
*
6
*
7
* Description : classe permettant de versionner les référentiels selon le manuel technique
7
* Description : classe permettant de versionner les référentiels selon le manuel technique
8
* Utilisation : php script.php versionnage -p bdnff -a tout
8
* Utilisation : php script.php versionnage -p bdnff -a tout
9
*
9
*
10
//Auteur original :
10
//Auteur original :
11
* @author       Jean-Pascal MILCENT <jpm@tela-botanica.org>
11
* @author       Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
* @copyright	Tela-Botanica 1999-2010
12
* @copyright	Tela-Botanica 1999-2010
13
* @link			http://www.tela-botanica.org/wikini/RTaxMethodo/wakka.php?wiki=MaNuel
13
* @link			http://www.tela-botanica.org/wikini/RTaxMethodo/wakka.php?wiki=MaNuel
14
* @licence		GPL v3 & CeCILL v2
14
* @licence		GPL v3 & CeCILL v2
15
* @version		$Id$
15
* @version		$Id$
16
*/
16
*/
17
// +-------------------------------------------------------------------------------------------------------------------+
17
// +-------------------------------------------------------------------------------------------------------------------+
18
// TODO : supprimer l'utilisation du paramêtres 'p' et chercher les infos depuis la bdd
18
// TODO : supprimer l'utilisation du paramêtres 'p' et chercher les infos depuis la bdd
19
class Versionnage extends ScriptCommande {
19
class Versionnage extends ScriptCommande {
20
	
20
	
21
	const SCRIPT_NOM = 'versionnage';
21
	const SCRIPT_NOM = 'versionnage';
-
 
22
	const MANUEL_VERSION = "2.1";
22
	
23
	
23
	private $projet = null;
24
	private $projet = null;
24
	private $traitement = null;
25
	private $traitement = null;
25
	private $meta = null;
26
	private $meta = null;
-
 
27
	private $version_courante = null;
26
	private $messages = null;
28
	private $messages = null;
27
	private $manuel = null;
29
	private $manuel = null;
-
 
30
	private $manuel_nom = null;
-
 
31
	private $manuel_chemin = null;
-
 
32
	private $zip_chemin_dossier = null;
-
 
33
	private $zip_chemin_fichier = null;
-
 
34
	
28
	private $noms = null;
35
	private $noms = null;
29
	private $noms_precedents = null;
36
	private $noms_precedents = null;
30
	private $noms_stat = null;
37
	private $noms_stat = null;
31
	private $champs_ordre = null;
38
	private $champs_ordre = null;
32
	private $champs_nom = null;
39
	private $champs_nom = null;
33
	private $diff_modif_types = null;
40
	private $diff_modif_types = null;
34
	private $signature_md5 = null;
41
	private $signature_md5 = null;
35
	
42
	
36
	private $resultatDao = null;
43
	private $resultatDao = null;
37
	private $traitementDao = null;
44
	private $traitementDao = null;
38
	private $metaDao = null;
45
	private $metaDao = null;
39
	private $tableStructureDao = null;
46
	private $tableStructureDao = null;
40
	private $referentielDao = null;
47
	private $referentielDao = null;
41
	
48
	
42
	public function executer() {
49
	public function executer() {
43
		// Récupération de paramêtres
50
		// Récupération de paramêtres
44
		$this->projet = $this->getParam('p');
51
		$this->projet = $this->getParam('p');
45
		
52
		
46
		// Récupération du dernier traitement demandé
53
		// Récupération du dernier traitement demandé
47
		$this->traitementDao = new TraitementDao();
54
		$this->traitementDao = new TraitementDao();
48
		$this->traitement = $this->traitementDao->getDernierTraitement($this->projet, self::SCRIPT_NOM);
55
		$this->traitement = $this->traitementDao->getDernierTraitement($this->projet, self::SCRIPT_NOM);
49
		if (isset($this->traitement)) {
56
		if (isset($this->traitement)) {
50
			Debug::printr($this->traitement);
57
			Debug::printr($this->traitement);
51
			// Écriture de la date de début du traitement
58
			// Écriture de la date de début du traitement
52
			Debug::printr('Debute:'.$this->traitementDao->debuterTraitement($this->traitement['id_traitement']));
59
			Debug::printr('Debute:'.$this->traitementDao->debuterTraitement($this->traitement['id_traitement']));
53
			
60
			
54
			// Nettoyage des traitements obsolètes
61
			// Nettoyage des traitements obsolètes
55
			$traitements_obsoletes = $this->traitementDao->getTraitementsObsoletes($this->projet, self::SCRIPT_NOM);
62
			$traitements_obsoletes = $this->traitementDao->getTraitementsObsoletes($this->projet, self::SCRIPT_NOM);
56
			if (isset($traitements_obsoletes)) {
63
			if (isset($traitements_obsoletes)) {
57
				Debug::printr('Supp. obsoletes:'.$this->traitementDao->supprimer($traitements_obsoletes));
64
				Debug::printr('Supp. obsoletes:'.$this->traitementDao->supprimer($traitements_obsoletes));
58
			}
65
			}
59
			
66
			
60
			// Lancement du test demandé
67
			// Lancement du test demandé
61
			$cmd = $this->getParam('a');
68
			$cmd = $this->getParam('a');
62
	    	switch ($cmd) {
69
	    	switch ($cmd) {
63
				case 'tout' :
70
				case 'tout' :
64
					$this->metaDao = new MetaDao();
71
					$this->initialiserScript();
65
					$this->resultatDao = new ResultatDao();
-
 
66
					$this->referentielDao = new ReferentielDao();
-
 
67
					$this->manuel = parse_ini_file(Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS.'referentiel_v2.1.ini');
-
 
68
					Debug::printr('Départ lancement versionnage:');
72
					Debug::printr('Départ lancement versionnage:');
69
					$this->lancerVersionnage();
73
					$this->lancerVersionnage();
70
					break;
74
					break;
71
				default :
75
				default :
72
					$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
76
					$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
73
			}
77
			}
74
			// Écriture de la date de fin du traitement
78
			// Écriture de la date de fin du traitement
75
			Debug::printr('Termine:'.$this->traitementDao->terminerTraitement($this->traitement['id_traitement']));
79
			Debug::printr('Termine:'.$this->traitementDao->terminerTraitement($this->traitement['id_traitement']));
76
		}
80
		}
77
    }
81
    }
78
 
82
	
-
 
83
    private function initialiserScript() {
-
 
84
		$this->metaDao = new MetaDao();
-
 
85
		$this->resultatDao = new ResultatDao();
-
 
86
		$this->referentielDao = new ReferentielDao();
-
 
87
		
-
 
88
		$this->manuel_nom = 'mtpr_v'.str_replace('.', '_', self::MANUEL_VERSION).'.pdf';
-
 
89
		$this->manuel_chemin = Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS;
-
 
90
		
-
 
91
		$manuel_config_nom = 'referentiel_v'.self::MANUEL_VERSION.'.ini';
-
 
92
		$this->manuel = parse_ini_file($this->manuel_chemin.$manuel_config_nom);
-
 
93
	}
-
 
94
	
79
    public function lancerVersionnage() {
95
    public function lancerVersionnage() {
80
		$this->chargerTraitementParametre();
96
		$this->chargerTraitementParametre();
-
 
97
		$this->initialiserNomVersionCOurante();
-
 
98
		$this->initialiserCheminsZip();
-
 
99
		$this->creerDossierZip();
81
		$this->archiver();
100
		$this->archiver();
82
    	$this->chargerNomsATraiter();
101
    	$this->chargerNomsATraiter();
83
    	$this->analyserNomsATraiter();
102
    	$this->analyserNomsATraiter();
84
		$this->creerFichiers();
103
		$this->creerFichiers();
-
 
104
		$this->nettoyerFichiers();
85
		$this->traiterMessages();
105
		$this->traiterMessages();
86
	}
106
	}
87
	
107
	
88
	private function chargerTraitementParametre() {
108
	private function chargerTraitementParametre() {
89
		$this->meta = unserialize($this->traitement['script_parametres']);
109
		$this->meta = unserialize($this->traitement['script_parametres']);
90
	}
110
	}
91
	
111
	
92
	private function archiver() {
112
	private function archiver() {
93
		$ok = $this->referentielDao->archiver($this->projet, $this->meta['version']);
113
		$ok = $this->referentielDao->archiver($this->projet, $this->meta['version']);
94
		if ($ok) {
114
		if ($ok) {
95
			$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a réussi";
115
			$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a réussi";
96
			$this->ajouterMessage($m);
116
			$this->ajouterMessage($m);
97
		} else {
117
		} else {
98
			$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a échoué";
118
			$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a échoué";
99
			$this->ajouterMessage($m);
119
			$this->ajouterMessage($m);
100
		}
120
		}
101
	}
121
	}
-
 
122
	
-
 
123
	private function initialiserNomVersionCOurante() {
-
 
124
		$this->version_courante = strtolower($this->projet).'_v'.str_replace('.', '_', $this->meta['version']);
-
 
125
		Debug::printr("Nom archive courante :".$this->version_courante);
-
 
126
	}
-
 
127
	
-
 
128
	private function initialiserCheminsZip() {
-
 
129
		$this->zip_chemin_dossier = Config::get('chemin_referentiel_zip').$this->version_courante.DIRECTORY_SEPARATOR;
-
 
130
		$this->zip_chemin_fichier = Config::get('chemin_referentiel_zip').$this->version_courante.'.zip';
-
 
131
	}
-
 
132
	
-
 
133
	private function creerDossierZip() {
-
 
134
		$recursivite = true;
-
 
135
		if (mkdir($this->zip_chemin_dossier, 0777, $recursivite) === false) {
-
 
136
			$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier' devant contenir les fichiers a échouée.");
-
 
137
		}
-
 
138
	}
102
	
139
	
103
	private function chargerNomsATraiter() {
-
 
104
		$archive_courante = strtolower($this->projet).'_v'.str_replace('.', '_', $this->meta['version']);
-
 
105
		Debug::printr("Nom archive courante :".$archive_courante);
140
	private function chargerNomsATraiter() {
106
		$this->noms = $this->referentielDao->getTout($archive_courante);
141
		$this->noms = $this->referentielDao->getTout($this->version_courante);
107
	}
142
	}
108
	
143
	
109
	private function analyserNomsATraiter() {
144
	private function analyserNomsATraiter() {
110
		$this->noms_stat['combinaison'] = $this->getNombreCombinaison();
145
		$this->noms_stat['combinaison'] = $this->getNombreCombinaison();
111
		$this->noms_stat['taxon'] = $this->getNombreTaxon();
146
		$this->noms_stat['taxon'] = $this->getNombreTaxon();
112
		Debug::printr("Stats :".print_r($this->noms_stat, true));
147
		Debug::printr("Stats :".print_r($this->noms_stat, true));
113
	}
148
	}
114
	
149
	
115
	private function getNombreCombinaison() {
150
	private function getNombreCombinaison() {
116
		return count($this->noms);
151
		return count($this->noms);
117
	}
152
	}
118
	
153
	
119
	private function getNombreTaxon() {
154
	private function getNombreTaxon() {
120
		$nbre = 0;
155
		$nbre = 0;
121
		foreach ($this->noms as $nom) {
156
		foreach ($this->noms as $nom) {
122
			if ($nom['num_nom_retenu'] == $nom['num_nom']) {
157
			if ($nom['num_nom_retenu'] == $nom['num_nom']) {
123
				$nbre++;
158
				$nbre++;
124
			}
159
			}
125
		}
160
		}
126
		return $nbre;
161
		return $nbre;
127
	}
162
	}
128
	
163
	
129
	private function creerFichiers() {
164
	private function creerFichiers() {
130
		// Respecter l'ordre de traitement : BDNT puis DIFF puis META
165
		// Respecter l'ordre de traitement : BDNT puis DIFF puis META
131
		$this->creerFichierBdnt();
166
		$this->creerFichierBdnt();
132
		$this->creerFichierDiff();
167
		$this->creerFichierDiff();
133
		$this->creerFichierMeta();
168
		$this->creerFichierMeta();
-
 
169
		$this->nettoyerMemoire();
-
 
170
		$this->copierManuel();
-
 
171
		$this->creerFichierZip();
134
	}
172
	}
135
	
173
	
136
	private function creerFichierBdnt() {
174
	private function creerFichierBdnt() {
137
		$noms =& $this->noms;
175
		$noms =& $this->noms;
138
		reset($this->noms);
176
		reset($this->noms);
139
		Debug::printr("Element courrant du tableau des noms : ".count($this->noms).'-'.print_r(current($this->noms),true));
177
		Debug::printr("Element courrant du tableau des noms : ".count($this->noms).'-'.print_r(current($this->noms),true));
140
		
178
		
141
		$this->determinerOrdreDesChamps();
179
		$this->determinerOrdreDesChamps();
142
		$this->definirNomDesChamps();
180
		$this->definirNomDesChamps();
143
		
181
		
144
		$donnees = array();
182
		$donnees = array();
145
		$donnees['champs'] = $this->champs_nom;
183
		$donnees['champs'] = $this->champs_nom;
146
		foreach ($this->noms as &$nom) {
184
		foreach ($this->noms as &$nom) {
147
			$infos = array();
185
			$infos = array();
148
			foreach ($nom as $champ => &$valeur) {
186
			foreach ($nom as $champ => &$valeur) {
149
				if (isset($this->champs_ordre[$champ])) {
187
				if (isset($this->champs_ordre[$champ])) {
150
					$ordre = $this->champs_ordre[$champ];
188
					$ordre = $this->champs_ordre[$champ];
151
					$infos[(int) $ordre] = trim($valeur);
189
					$infos[(int) $ordre] = trim($valeur);
152
				} else {
190
				} else {
153
					$e = "Le champ '$champ' n'a pas été pris en compte dans l'attribution de l'ordre des champs.";
191
					$e = "Le champ '$champ' n'a pas été pris en compte dans l'attribution de l'ordre des champs.";
154
					$this->ajouterMessage($e);
192
					$this->ajouterMessage($e);
155
				}
193
				}
156
			}
194
			}
157
			ksort($infos);
195
			ksort($infos);
158
			$donnees['noms'][] = $infos;
196
			$donnees['noms'][] = $infos;
159
		}
197
		}
160
		Debug::printr("Dernier element du tableau des noms [trié] : ".print_r($infos,true));
198
		Debug::printr("Dernier element du tableau des noms [trié] : ".print_r($infos,true));
161
		$bdnt_tsv = $this->getVue('versionnage/squelettes/bdnt', $donnees, '.tpl.tsv');
199
		$bdnt_tsv = $this->getVue('versionnage/squelettes/bdnt', $donnees, '.tpl.tsv');
162
		$this->ecrireFichierBdnt($bdnt_tsv);
200
		$this->ecrireFichierBdnt($bdnt_tsv);
163
	}
201
	}
164
	
202
	
165
	private function determinerOrdreDesChamps() {
203
	private function determinerOrdreDesChamps() {
166
		$champs_ordre = explode(',', $this->manuel['champs']);
204
		$champs_ordre = explode(',', $this->manuel['champs']);
167
		$champs_ordre = array_flip($champs_ordre);
205
		$champs_ordre = array_flip($champs_ordre);
168
		$nom_courant = current($this->noms);
206
		$nom_courant = current($this->noms);
169
		$champs_ordre = $this->attribuerOrdreChampsSupplémentaires($champs_ordre, $nom_courant);
207
		$champs_ordre = $this->attribuerOrdreChampsSupplémentaires($champs_ordre, $nom_courant);
170
		asort($champs_ordre);
208
		asort($champs_ordre);
171
		$this->champs_ordre = $champs_ordre;
209
		$this->champs_ordre = $champs_ordre;
172
		Debug::printr("Ordre des champs : ".print_r($this->champs_ordre,true));
210
		Debug::printr("Ordre des champs : ".print_r($this->champs_ordre,true));
173
	}
211
	}
174
	
212
	
175
	private function definirNomDesChamps() {
213
	private function definirNomDesChamps() {
176
		$this->champs_nom = array_flip($this->champs_ordre);
214
		$this->champs_nom = array_flip($this->champs_ordre);
177
	}
215
	}
178
	
216
	
179
	private function attribuerOrdreChampsSupplémentaires($champs_ordre, $nom) {
217
	private function attribuerOrdreChampsSupplémentaires($champs_ordre, $nom) {
180
		foreach ($nom as $champ => $info) {
218
		foreach ($nom as $champ => $info) {
181
			if (!isset($champs_ordre[$champ])) {
219
			if (!isset($champs_ordre[$champ])) {
182
				$champs_ordre[$champ] = count($champs_ordre);
220
				$champs_ordre[$champ] = count($champs_ordre);
183
			}
221
			}
184
		}
222
		}
185
		return $champs_ordre;
223
		return $champs_ordre;
186
	}
224
	}
187
	
225
	
188
	private function ajouterMessage($message) {
226
	private function ajouterMessage($message) {
189
		$titre = self::SCRIPT_NOM.' #'.$this->traitement['id_traitement'];
227
		$titre = self::SCRIPT_NOM.' #'.$this->traitement['id_traitement'];
190
		$this->messages[] = array('message' => $message, 'resultat' => true);
228
		$this->messages[] = array('message' => $message, 'resultat' => true);
191
	}
229
	}
192
	
230
	
193
	private function ecrireFichierBdnt($contenu) {
231
	private function ecrireFichierBdnt($contenu) {
194
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_ref'];
232
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_bdnt'];
195
		$fichier_chemin = Config::get('chemin_referentiel_zip').$fichier_nom;
233
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
196
		
234
		
197
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
235
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
198
			$this->ajouterMessage("Écriture du fichier bdnt réussie.");
236
			$this->ajouterMessage("Écriture du fichier bdnt réussie.");
199
			$this->signature_md5 = md5_file($fichier_chemin);
237
			$this->signature_md5 = md5_file($fichier_chemin);
200
			$this->ajouterMessage("Signature MD5 du fichier bdnt :".$this->signature_md5);
238
			$this->ajouterMessage("Signature MD5 du fichier bdnt :".$this->signature_md5);
201
			$this->ajouterMessage("Nombre de combinaisons traités : ".$this->noms_stat['combinaison']);
239
			$this->ajouterMessage("Nombre de combinaisons traités : ".$this->noms_stat['combinaison']);
202
		}
240
		}
203
	}
241
	}
204
	
242
	
205
	private function getBaseNomFichier() {
243
	private function getBaseNomFichier() {
206
		return strtolower($this->meta['acronyme'].'_v'.$this->meta['version']);
244
		return strtolower($this->meta['acronyme'].'_v'.$this->meta['version']);
207
	}
245
	}
208
	
246
	
209
	private function ecrireFichier($fichier_chemin, $contenu) {
247
	private function ecrireFichier($fichier_chemin, $contenu) {
210
		$retour = true;
248
		$retour = true;
211
		if (file_put_contents($fichier_chemin, $contenu) == false) {
249
		if (file_put_contents($fichier_chemin, $contenu) == false) {
212
			$e = "Une erreur est survenu lors de l'écriture du fichier : $fichier_chemin";
250
			$e = "Une erreur est survenu lors de l'écriture du fichier : $fichier_chemin";
213
			$this->ajouterMessage($e);
251
			$this->ajouterMessage($e);
214
			$retour = false;
252
			$retour = false;
215
		}
253
		}
216
		return $retour;
254
		return $retour;
217
	}
255
	}
218
	
256
	
219
	private function creerFichierDiff() {
257
	private function creerFichierDiff() {
220
		$derniere_meta = $this->metaDao->getDerniere($this->projet);
258
		$derniere_meta = $this->metaDao->getDerniere($this->projet);
221
		if (is_null($derniere_meta === false)) {
259
		if (is_null($derniere_meta === false)) {
222
			$this->ajouterMessage("Un problème est survenu lors de la récupération des métadonnées précédentes.");
260
			$this->ajouterMessage("Un problème est survenu lors de la récupération des métadonnées précédentes.");
223
		} else if (is_null($derniere_meta)) {
261
		} else if (is_null($derniere_meta)) {
224
			$this->ajouterMessage("Premier versionnage pour ce projet, aucun fichier différentiel ne sera créé.");
262
			$this->ajouterMessage("Premier versionnage pour ce projet, aucun fichier différentiel ne sera créé.");
225
		} else {
263
		} else {
226
			Debug::printr("Méta dernier enregistrement : ".print_r($derniere_meta,true));
-
 
227
			$code_projet_precedent = strtolower($derniere_meta['code']).'_v'.str_replace('.', '_', $derniere_meta['version']);
264
			$code_projet_precedent = strtolower($derniere_meta['code']).'_v'.str_replace('.', '_', $derniere_meta['version']);
228
			Debug::printr("Code projet précédent : $code_projet_precedent");
265
			if ($code_projet_precedent == $this->version_courante) {
-
 
266
				$e = "La code de la version préalablement versionnée ($code_projet_precedent) est le même que celui ".
-
 
267
					"de la demande actuel ({$this->version_courante}) pour ce projet, aucun fichier différentiel ne sera créé.";
-
 
268
				$this->ajouterMessage($e);
-
 
269
			} else {
229
			$this->noms_precedents = $this->referentielDao->getTout($code_projet_precedent);
270
				$this->noms_precedents = $this->referentielDao->getTout($code_projet_precedent);
230
			$donnees = array();
271
				$donnees = array();
231
			$donnees['diff'] = $this->realiserDiff();
272
				$donnees['diff'] = $this->realiserDiff();
232
			$donnees['champs'] = $this->champs_nom;
273
				$donnees['champs'] = $this->champs_nom;
233
			$diff_tsv = $this->getVue('versionnage/squelettes/diff', $donnees, '.tpl.tsv');
274
				$diff_tsv = $this->getVue('versionnage/squelettes/diff', $donnees, '.tpl.tsv');
234
			$this->ecrireFichierDiff($diff_tsv);
275
				$this->ecrireFichierDiff($diff_tsv);
-
 
276
			}
235
		}
277
		}
236
	}
278
	}
237
	
279
	
238
	private function realiserDiff() {
280
	private function realiserDiff() {
239
		$diff = array();
281
		$diff = array();
240
		$this->noms_stat['modification'] = 0;
282
		$this->noms_stat['modification'] = 0;
241
		foreach ($this->noms as $id => &$nom) {
283
		foreach ($this->noms as $id => &$nom) {
242
			if (!isset($this->noms_precedents[$id])) {
284
			if (!isset($this->noms_precedents[$id])) {
243
				$diff[$id] = $nom;
285
				$diff[$id] = $nom;
244
				$diff[$id]['modification_type'] = 'A';
286
				$diff[$id]['modification_type'] = 'A';
245
				$diff[$id]['modification_type_1'] = '0';
287
				$diff[$id]['modification_type_1'] = '0';
246
				$diff[$id]['modification_type_2'] = '0';
288
				$diff[$id]['modification_type_2'] = '0';
247
				$diff[$id]['modification_type_3'] = '0';
289
				$diff[$id]['modification_type_3'] = '0';
248
				$this->noms_stat['modification']++;
290
				$this->noms_stat['modification']++;
249
			} else {
291
			} else {
250
				$nom_precedent =& $this->noms_precedents[$id];
292
				$nom_precedent =& $this->noms_precedents[$id];
251
				$nom_diff = array_diff_assoc($nom, $nom_precedent);
293
				$nom_diff = array_diff_assoc($nom, $nom_precedent);
252
				if (count($nom_diff) > 0) {
294
				if (count($nom_diff) > 0) {
253
					$this->noms_stat['modification']++;
295
					$this->noms_stat['modification']++;
254
					$modif['modification_type'] = 'M';
296
					$modif['modification_type'] = 'M';
255
					$modif['modification_type_1'] = '0';
297
					$modif['modification_type_1'] = '0';
256
					$modif['modification_type_2'] = '0';
298
					$modif['modification_type_2'] = '0';
257
					$modif['modification_type_3'] = '0';
299
					$modif['modification_type_3'] = '0';
258
					$this->chargerTableauChampsModifTypes();
300
					$this->chargerTableauChampsModifTypes();
259
					foreach ($this->champs_nom as $champ) {
301
					foreach ($this->champs_nom as $champ) {
260
						if (isset($nom_diff[$champ])) {
302
						if (isset($nom_diff[$champ])) {
261
							$diff[$id][$champ] = $nom_diff[$champ];
303
							$diff[$id][$champ] = $nom_diff[$champ];
262
							$type = $this->getDiffType($champ);
304
							$type = $this->getDiffType($champ);
263
							$modif['modification_type_'.$type] = '1';
305
							$modif['modification_type_'.$type] = '1';
264
						} else {
306
						} else {
265
							$diff[$id][$champ] = '';
307
							$diff[$id][$champ] = '';
266
						}
308
						}
267
					}
309
					}
268
					foreach ($modif as $cle => $val) {
310
					foreach ($modif as $cle => $val) {
269
						$diff[$id][$cle] = $val;
311
						$diff[$id][$cle] = $val;
270
					}
312
					}
271
				}
313
				}
272
			}
314
			}
273
		}
315
		}
274
		return $diff;
316
		return $diff;
275
	}
317
	}
276
	
318
	
277
	private function chargerTableauChampsModifTypes() {
319
	private function chargerTableauChampsModifTypes() {
278
		$champs = explode(',', $this->manuel['champs_diff_type']);
320
		$champs = explode(',', $this->manuel['champs_diff_type']);
279
		foreach ($champs as $champ) {
321
		foreach ($champs as $champ) {
280
			list($champ_nom, $type) = explode('=', $champ);
322
			list($champ_nom, $type) = explode('=', $champ);
281
			$this->diff_modif_types[$champ_nom] = $type;
323
			$this->diff_modif_types[$champ_nom] = $type;
282
		}
324
		}
283
	}
325
	}
284
	
326
	
285
	private function getDiffType($champ_nom) {
327
	private function getDiffType($champ_nom) {
286
		$type = isset($this->diff_modif_types[$champ_nom]) ? $this->diff_modif_types[$champ_nom] : '3';
328
		$type = isset($this->diff_modif_types[$champ_nom]) ? $this->diff_modif_types[$champ_nom] : '3';
287
		return $type;
329
		return $type;
288
	}
330
	}
289
	
331
	
290
	private function ecrireFichierDiff($contenu) {
332
	private function ecrireFichierDiff($contenu) {
291
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_diff'];
333
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_diff'];
292
		$fichier_chemin = Config::get('chemin_referentiel_zip').$fichier_nom;
334
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
293
		
335
		
294
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
336
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
295
			$this->ajouterMessage("Écriture du fichier diff réussie.");
337
			$this->ajouterMessage("Écriture du fichier diff réussie.");
296
		}
338
		}
297
	}
339
	}
298
	
340
	
299
	private function creerFichierMeta() {
341
	private function creerFichierMeta() {
300
		$donnees = array();
342
		$donnees = array();
301
		$donnees = $this->meta;
343
		$donnees = $this->meta;
302
		$donnees['stats'] = $this->noms_stat;
344
		$donnees['stats'] = $this->noms_stat;
303
		$donnees['signature'] = $this->signature_md5;
345
		$donnees['signature'] = $this->signature_md5;
304
		$meta_tsv = $this->getVue('versionnage/squelettes/meta', $donnees, '.tpl.tsv');
346
		$meta_tsv = $this->getVue('versionnage/squelettes/meta', $donnees, '.tpl.tsv');
305
		$this->ecrireFichierMeta($meta_tsv);
347
		$this->ecrireFichierMeta($meta_tsv);
306
	}
348
	}
307
	
349
	
308
	private function ecrireFichierMeta($contenu) {
350
	private function ecrireFichierMeta($contenu) {
309
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_meta'];
351
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_meta'];
310
		$fichier_chemin = Config::get('chemin_referentiel_zip').$fichier_nom;
352
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
311
		
353
		
312
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
354
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
313
			$this->ajouterMessage("Écriture du fichier meta réussie.");
355
			$this->ajouterMessage("Écriture du fichier meta réussie.");
314
			$this->archiverMetadonnees();
356
			$this->archiverMetadonnees();
315
		}
357
		}
316
	}
358
	}
317
	
359
	
318
	private function archiverMetadonnees() {
360
	private function archiverMetadonnees() {
319
		$metadonnees = $this->meta;
361
		$metadonnees = $this->meta;
320
		$metadonnees['code'] = $this->meta['acronyme'];
362
		$metadonnees['code'] = $this->meta['acronyme'];
321
		unset($metadonnees['acronyme']);
363
		unset($metadonnees['acronyme']);
322
		$metadonnees['domaine_taxo'] = $this->meta['dom_tax'];
364
		$metadonnees['domaine_taxo'] = $this->meta['dom_tax'];
323
		unset($metadonnees['dom_tax']);
365
		unset($metadonnees['dom_tax']);
324
		$metadonnees['domaine_geo'] = $this->meta['dom_geo'];
366
		$metadonnees['domaine_geo'] = $this->meta['dom_geo'];
325
		unset($metadonnees['dom_geo']);
367
		unset($metadonnees['dom_geo']);
326
		$metadonnees['domaine_nom'] = $this->meta['dom_code'];
368
		$metadonnees['domaine_nom'] = $this->meta['dom_code'];
327
		unset($metadonnees['dom_code']);
369
		unset($metadonnees['dom_code']);
328
		$metadonnees['auteur'] = $this->meta['auteur_principal'];
370
		$metadonnees['auteur'] = $this->meta['auteur_principal'];
329
		unset($metadonnees['auteur_principal']);
371
		unset($metadonnees['auteur_principal']);
330
		$metadonnees['date_production'] = $this->meta['date_prod'];
372
		$metadonnees['date_production'] = $this->meta['date_prod'];
331
		unset($metadonnees['date_prod']);
373
		unset($metadonnees['date_prod']);
332
		$metadonnees['droit'] = $this->meta['copyright'];
374
		$metadonnees['droit'] = $this->meta['copyright'];
333
		unset($metadonnees['copyright']);
375
		unset($metadonnees['copyright']);
334
		
376
		
335
		$ok = $this->metaDao->ajouter($metadonnees);
377
		$ok = $this->metaDao->ajouter($metadonnees);
336
		if ($ok === false) {
378
		if ($ok === false) {
337
			$this->ajouterMessage("L'archivage des métadonnées a échoué.");
379
			$this->ajouterMessage("L'archivage des métadonnées a échoué.");
338
		}
380
		}
-
 
381
	}
-
 
382
	
-
 
383
	private function nettoyerMemoire() {
-
 
384
		$this->noms = null;
-
 
385
		$this->noms_precedents = null;
-
 
386
		$this->noms_stat = null; 
-
 
387
	}
-
 
388
	
-
 
389
	private function copierManuel() {
-
 
390
		$fichier_source = $this->manuel_chemin.$this->manuel_nom;
-
 
391
		$fichier_destination = $this->zip_chemin_dossier.$this->manuel_nom;
-
 
392
		if (copy($fichier_source, $fichier_destination) === false) {
-
 
393
			$this->ajouterMessage("La copie du manuel '$fichier_destination' a échouée.");
-
 
394
		}
-
 
395
	}
-
 
396
	
-
 
397
	private function creerFichierZip() {
-
 
398
		$fichierZip = new PclZip($this->zip_chemin_fichier);
-
 
399
		if ($fichierZip->add($this->zip_chemin_dossier, PCLZIP_OPT_REMOVE_ALL_PATH) == 0) {
-
 
400
			$e = "La création du fichier zip '$this->zip_chemin_fichier' a échoué avec l'erreur : ".$fichierZip>errorInfo(true);
-
 
401
			$this->ajouterMessage($e);
-
 
402
		}	
-
 
403
	}
-
 
404
	
-
 
405
	private function nettoyerFichiers() {
-
 
406
		$dossier = $this->zip_chemin_dossier;
-
 
407
		if (is_dir($dossier)) {
-
 
408
			$objets = scandir($dossier);
-
 
409
			foreach ($objets as $objet) {
-
 
410
				if ($objet != '.' && $objet != '..') {
-
 
411
					if (filetype($dossier.'/'.$objet) == 'dir') {
-
 
412
						rrmdir($dossier.'/'.$objet);
-
 
413
					} else {
-
 
414
						unlink($dossier.'/'.$objet);
-
 
415
					}
-
 
416
				}
-
 
417
			}
-
 
418
			reset($objets);
-
 
419
			rmdir($dossier);
-
 
420
		}
339
	}
421
	}
340
	
422
	
341
	private function traiterMessages() {
423
	private function traiterMessages() {
342
		if (isset($this->messages)) {
424
		if (isset($this->messages)) {
343
			$num_message = 1;
425
			$num_message = 1;
344
			foreach ($this->messages as $message) {
426
			foreach ($this->messages as $message) {
345
				$message['nom'] = 'Message #'.$num_message++;
427
				$message['nom'] = 'Message #'.$num_message++;
346
				$this->resultatDao->ajouter($this->traitement['id_traitement'], $message);
428
				$this->resultatDao->ajouter($this->traitement['id_traitement'], $message);
347
			}
429
			}
348
		}
430
		}
349
	}
431
	}
350
}
432
}
351
?>
433
?>