Subversion Repositories Applications.referentiel

Rev

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

Rev 215 Rev 216
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 : lors de la génération de la version 2 de la BDTFX tester les diff! Il se peut que la mémoire soit dépassée.
18
// TODO : lors de la génération de la version 2 de la BDTFX tester les diff! Il se peut que la mémoire soit dépassée.
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 = '4.2';
22
	const MANUEL_VERSION = '4.2';
23
	
23
	
24
	private $projet = null;
24
	private $projet = null;
25
	private $traitement = null;
25
	private $traitement = null;
26
	private $meta = null;
26
	private $meta = null;
27
	private $version_courante = null;
27
	private $version_courante = null;
28
	private $messages = null;
28
	private $messages = null;
29
	private $manuel = null;
29
	private $manuel = null;
30
	private $manuel_nom = null;
30
	private $manuel_nom = null;
31
	private $manuel_chemin = null;
31
	private $manuel_chemin = null;
32
	private $zip_chemin_dossier = null;
32
	private $zip_chemin_dossier = null;
33
	private $zip_chemin_fichier = null;
33
	private $zip_chemin_fichier = null;
34
	private $zip_chemin_dossier_partiel = null;
34
	private $zip_chemin_dossier_partiel = null;
35
	private $zip_chemin_fichier_partiel = null;
35
	private $zip_chemin_fichier_partiel = null;
36
	
36
	
37
	private $noms = null;
37
	private $noms = null;
38
	private $noms_precedents = null;
38
	private $noms_precedents = null;
-
 
39
	private $noms_supprimes = null;
39
	private $noms_stat = null;
40
	private $noms_stat = null;
40
	private $noms_stat_partiel = null;
41
	private $noms_stat_partiel = null;
41
	private $champs_ordre = null;
42
	private $champs_ordre = null;
42
	private $champs_nom = null;
43
	private $champs_nom = null;
43
	private $champs_nom_partiel = null;
44
	private $champs_nom_partiel = null;
-
 
45
	private $champs_courants = null;
44
	private $champs_diff = null;
46
	private $champs_diff = null;
45
	private $diff_champs_nom = null;
47
	private $diff_champs_nom = null;
46
	private $diff_modif_types = null;
48
	private $diff_modif_types = null;
47
	private $signature_md5 = null;
49
	private $signature_md5 = null;
48
	private $signature_md5_partiel = null;
50
	private $signature_md5_partiel = null;
49
	private $exclure_taxref = null;
-
 
50
	
51
	
51
	private $resultatDao = null;
52
	private $resultatDao = null;
52
	private $traitementDao = null;
53
	private $traitementDao = null;
53
	private $metaDao = null;
54
	private $metaDao = null;
54
	private $tableStructureDao = null;
55
	private $tableStructureDao = null;
55
	private $referentielDao = null;
56
	private $referentielDao = null;
56
	
57
	
57
	public function executer() {
58
	public function executer() {
58
		// Récupération du dernier traitement demandé
59
		// Récupération du dernier traitement demandé
59
		$this->traitementDao = new TraitementDao();
60
		$this->traitementDao = new TraitementDao();
60
		$this->traitement = $this->traitementDao->getDernierTraitement('tout', self::SCRIPT_NOM);
61
		$this->traitement = $this->traitementDao->getDernierTraitement('tout', self::SCRIPT_NOM);
61
		if (isset($this->traitement)) {
62
		if (isset($this->traitement)) {
62
			$this->projet = $this->traitement['referentiel_code']; // Récupération du nom de projet
63
			$this->projet = $this->traitement['referentiel_code']; // Récupération du nom de projet
63
			Debug::printr($this->traitement);
64
			Debug::printr($this->traitement);
64
			// Écriture de la date de début du traitement
65
			// Écriture de la date de début du traitement
65
			Debug::printr('Debute:'.$this->traitementDao->debuterTraitement($this->traitement['id_traitement']));
66
			Debug::printr('Debute:'.$this->traitementDao->debuterTraitement($this->traitement['id_traitement']));
66
			
67
			
67
			// Nettoyage des traitements obsolètes
68
			// Nettoyage des traitements obsolètes
68
			$traitements_obsoletes = $this->traitementDao->getTraitementsObsoletes($this->projet, self::SCRIPT_NOM);
69
			$traitements_obsoletes = $this->traitementDao->getTraitementsObsoletes($this->projet, self::SCRIPT_NOM);
69
			if (isset($traitements_obsoletes)) {
70
			if (isset($traitements_obsoletes)) {
70
				Debug::printr('Supp. obsoletes:'.$this->traitementDao->supprimer($traitements_obsoletes));
71
				Debug::printr('Supp. obsoletes:'.$this->traitementDao->supprimer($traitements_obsoletes));
71
			}
72
			}
72
			
73
			
73
			// Lancement du test demandé
74
			// Lancement du test demandé
74
			$cmd = $this->getParam('a');
75
			$cmd = $this->getParam('a');
75
	    	switch ($cmd) {
76
	    	switch ($cmd) {
76
				case 'tout' :
77
				case 'tout' :
77
					$this->initialiserScript();
78
					$this->initialiserScript();
78
					Debug::printr('Départ lancement versionnage:');
79
					Debug::printr('Départ lancement versionnage:');
79
					$this->lancerVersionnage();
80
					$this->lancerVersionnage();
80
					break;
81
					break;
81
				default :
82
				default :
82
					$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
83
					$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
83
			}
84
			}
84
			// Écriture de la date de fin du traitement
85
			// Écriture de la date de fin du traitement
85
			Debug::printr('Termine:'.$this->traitementDao->terminerTraitement($this->traitement['id_traitement']));
86
			Debug::printr('Termine:'.$this->traitementDao->terminerTraitement($this->traitement['id_traitement']));
86
		}
87
		}
87
    }
88
    }
88
	
89
	
89
    private function initialiserScript() {
90
    private function initialiserScript() {
90
		$this->metaDao = new MetaDao();
91
		$this->metaDao = new MetaDao();
91
		$this->resultatDao = new ResultatDao();
92
		$this->resultatDao = new ResultatDao();
92
		$this->referentielDao = new ReferentielDao();
93
		$this->referentielDao = new ReferentielDao();
93
		
94
		
94
		$this->manuel_nom = 'mtpr_v'.str_replace('.', '_', self::MANUEL_VERSION).'.pdf';
95
		$this->manuel_nom = 'mtpr_v'.str_replace('.', '_', self::MANUEL_VERSION).'.pdf';
95
		$this->manuel_chemin = Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS;
96
		$this->manuel_chemin = Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS;
96
		
97
		
97
		$manuel_config_nom = 'referentiel_v'.self::MANUEL_VERSION.'.ini';
98
		$manuel_config_nom = 'referentiel_v'.self::MANUEL_VERSION.'.ini';
98
		$this->manuel = parse_ini_file($this->manuel_chemin.$manuel_config_nom);
99
		$this->manuel = parse_ini_file($this->manuel_chemin.$manuel_config_nom);
99
	}
100
	}
100
	
101
	
101
    public function lancerVersionnage() {
102
    public function lancerVersionnage() {
102
		$this->chargerTraitementParametre();
103
		$this->chargerTraitementParametre();
103
		$this->initialiserNomVersionCOurante();
104
		$this->initialiserNomVersionCOurante();
104
		$this->initialiserCheminsZip();
105
		$this->initialiserCheminsZip();
105
		$this->creerDossiersZip();
106
		$this->creerDossiersZip();
106
		$this->archiver();
107
		$this->archiver();
107
    	$this->chargerNomsATraiter();
108
    	$this->chargerNomsATraiter();
108
    	$this->analyserNomsATraiter();
109
    	$this->analyserNomsATraiter();
109
		$this->creerFichiers();
110
		$this->creerFichiers();
110
		$this->nettoyerFichiers();
111
		$this->nettoyerFichiers();
111
		$this->traiterMessages();
112
		$this->traiterMessages();
112
	}
113
	}
113
	
114
	
114
	private function chargerTraitementParametre() {
115
	private function chargerTraitementParametre() {
115
		$this->meta = unserialize($this->traitement['script_parametres']);
116
		$this->meta = unserialize($this->traitement['script_parametres']);
116
	}
117
	}
117
	
118
	
118
	private function archiver() {
119
	private function archiver() {
119
		$ok = $this->referentielDao->archiver($this->projet, $this->meta['version']);
120
		$ok = $this->referentielDao->archiver($this->projet, $this->meta['version']);
120
		if ($ok) {
121
		if ($ok) {
121
			$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a réussi";
122
			$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a réussi";
122
			$this->ajouterMessage($m);
123
			$this->ajouterMessage($m);
123
		} else {
124
		} else {
124
			$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a échoué";
125
			$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a échoué";
125
			$this->ajouterMessage($m);
126
			$this->ajouterMessage($m);
126
		}
127
		}
127
	}
128
	}
128
	
129
	
129
	private function initialiserNomVersionCOurante() {
130
	private function initialiserNomVersionCOurante() {
130
		$this->version_courante = strtolower($this->projet).'_v'.str_replace('.', '_', $this->meta['version']);
131
		$this->version_courante = strtolower($this->projet).'_v'.str_replace('.', '_', $this->meta['version']);
131
		Debug::printr("Nom archive courante :".$this->version_courante);
132
		Debug::printr("Nom archive courante :".$this->version_courante);
132
	}
133
	}
133
	
134
	
134
	private function initialiserCheminsZip() {
135
	private function initialiserCheminsZip() {
135
		$this->zip_chemin_dossier = Config::get('chemin_referentiel_zip').$this->version_courante.DIRECTORY_SEPARATOR;
136
		$this->zip_chemin_dossier = Config::get('chemin_referentiel_zip').$this->version_courante.DIRECTORY_SEPARATOR;
136
		$this->zip_chemin_fichier = Config::get('chemin_referentiel_zip').$this->version_courante.'.zip';
137
		$this->zip_chemin_fichier = Config::get('chemin_referentiel_zip').$this->version_courante.'.zip';
137
		$this->zip_chemin_dossier_partiel = Config::get('chemin_referentiel_zip').$this->version_courante.'_partiel'.DIRECTORY_SEPARATOR;
138
		$this->zip_chemin_dossier_partiel = Config::get('chemin_referentiel_zip').$this->version_courante.'_partiel'.DIRECTORY_SEPARATOR;
138
		$this->zip_chemin_fichier_partiel = Config::get('chemin_referentiel_zip').$this->version_courante.'_partiel.zip';
139
		$this->zip_chemin_fichier_partiel = Config::get('chemin_referentiel_zip').$this->version_courante.'_partiel.zip';
139
	}
140
	}
140
	
141
	
141
	private function creerDossiersZip() {
142
	private function creerDossiersZip() {
142
		$recursivite = true;
143
		$recursivite = true;
143
		if (mkdir($this->zip_chemin_dossier, 0777, $recursivite) === false) {
144
		if (mkdir($this->zip_chemin_dossier, 0777, $recursivite) === false) {
144
			$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier' devant contenir les fichiers a échouée.");
145
			$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier' devant contenir les fichiers a échouée.");
145
		}
146
		}
146
		if (mkdir($this->zip_chemin_dossier_partiel, 0777, $recursivite) === false) {
147
		if (mkdir($this->zip_chemin_dossier_partiel, 0777, $recursivite) === false) {
147
			$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier_partiel' devant contenir les fichiers partiels a échouée.");
148
			$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier_partiel' devant contenir les fichiers partiels a échouée.");
148
		}
149
		}
149
	}
150
	}
150
	
151
	
151
	private function chargerNomsATraiter() {
152
	private function chargerNomsATraiter() {
152
		$this->noms = $this->referentielDao->getTout($this->version_courante);
153
		$this->noms = $this->referentielDao->getTout($this->version_courante);
153
	}
154
	}
154
	
155
	
155
	private function analyserNomsATraiter() {
156
	private function analyserNomsATraiter() {
156
		$this->noms_stat['combinaison'] = $this->getNombreCombinaison();
157
		$this->noms_stat['combinaison'] = $this->getNombreCombinaison();
157
		$this->noms_stat['taxon'] = $this->getNombreTaxon();
158
		$this->noms_stat['taxon'] = $this->getNombreTaxon();
158
		Debug::printr("Stats :".print_r($this->noms_stat, true));
159
		Debug::printr("Stats :".print_r($this->noms_stat, true));
159
		$this->noms_stat_partiel = $this->getStatsPartiel();
160
		$this->noms_stat_partiel = $this->getStatsPartiel();
160
		Debug::printr("Stats partiel:".print_r($this->noms_stat_partiel, true));
161
		Debug::printr("Stats partiel:".print_r($this->noms_stat_partiel, true));
161
	}
162
	}
162
	
163
	
163
	private function getNombreCombinaison() {
164
	private function getNombreCombinaison() {
164
		return count($this->noms);
165
		return count($this->noms);
165
	}
166
	}
166
	
167
	
167
	private function getNombreTaxon() {
168
	private function getNombreTaxon() {
168
		$nbre = 0;
169
		$nbre = 0;
169
		foreach ($this->noms as $nom) {
170
		foreach ($this->noms as $nom) {
170
			if ($nom['num_nom_retenu'] == $nom['num_nom']) {
171
			if ($nom['num_nom_retenu'] == $nom['num_nom']) {
171
				$nbre++;
172
				$nbre++;
172
			}
173
			}
173
		}
174
		}
174
		return $nbre;
175
		return $nbre;
175
	}
176
	}
176
	
177
	
177
	private function getStatsPartiel() {
178
	private function getStatsPartiel() {
178
		$stat['combinaison'] = 0;
179
		$stat['combinaison'] = 0;
179
		$stat['taxon'] = 0;
180
		$stat['taxon'] = 0;
180
		foreach ($this->noms as $nom) {
181
		foreach ($this->noms as $nom) {
181
			if ($nom['exclure_taxref'] != '1') {
182
			if ($nom['exclure_taxref'] != '1') {
182
				$stat['combinaison']++;
183
				$stat['combinaison']++;
183
				if ($nom['num_nom_retenu'] == $nom['num_nom']) {
184
				if ($nom['num_nom_retenu'] == $nom['num_nom']) {
184
					$stat['taxon']++;
185
					$stat['taxon']++;
185
				}
186
				}
186
			}
187
			}
187
		}
188
		}
188
		return $stat;
189
		return $stat;
189
	}
190
	}
190
	
191
	
191
	private function creerFichiers() {
192
	private function creerFichiers() {
192
		// Respecter l'ordre de traitement : BDNT puis DIFF puis META
193
		// Respecter l'ordre de traitement : BDNT puis DIFF puis META
193
		$donnees =& $this->creerFichierBdnt();
194
		$donnees =& $this->creerFichierBdnt();
194
		$this->creerFichierBdntPartiel($donnees);
195
		$this->creerFichierBdntPartiel($donnees);
195
		$donnees = null;
196
		$donnees = null;
196
		$donnees =& $this->creerFichierDiff();
197
		$donnees =& $this->creerFichierDiff();
197
		$this->creerFichierDiffPartiel($donnees);
198
		$this->creerFichierDiffPartiel($donnees);
198
		$donnees = null;
199
		$donnees = null;
199
		$donnees =& $this->creerFichierMeta();
200
		$donnees =& $this->creerFichierMeta();
200
		$this->creerFichierMetaPartiel($donnees);
201
		$this->creerFichierMetaPartiel($donnees);
201
		$donnees = null;
202
		$donnees = null;
202
		$this->nettoyerMemoire();
203
		$this->nettoyerMemoire();
203
		$this->copierManuel();
204
		$this->copierManuel();
204
		$this->creerFichiersZip();
205
		$this->creerFichiersZip();
205
	}
206
	}
206
	
207
	
207
	private function creerFichierBdnt() {
208
	private function creerFichierBdnt() {
208
		reset($this->noms);
209
		reset($this->noms);
209
		Debug::printr("Element courrant du tableau des noms : ".count($this->noms).'-'.print_r(current($this->noms),true));
210
		Debug::printr("Element courrant du tableau des noms : ".count($this->noms).'-'.print_r(current($this->noms),true));
210
		
211
		
211
		$this->determinerOrdreDesChamps();
212
		$this->determinerOrdreDesChamps();
212
		$this->definirNomDesChamps();
213
		$this->definirNomDesChamps();
213
		$this->definirNomDesChampsDiff();
214
		$this->definirNomDesChampsDiff();
214
		
215
		
215
		$donnees = array();
216
		$donnees = array();
216
		$donnees['champs'] = $this->champs_nom;
217
		$donnees['champs'] = $this->champs_nom;
217
		
218
		
218
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_bdnt'];
219
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_bdnt'];
219
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
220
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
220
		$bdnt_tsv_entete = $this->getVue('versionnage/squelettes/bdnt_entete', array('champs' => $donnees['champs']), '.tpl.tsv');
221
		$bdnt_tsv_entete = $this->getVue('versionnage/squelettes/bdnt_entete', array('champs' => $donnees['champs']), '.tpl.tsv');
221
		$this->ecrireFichier($fichier_chemin, $bdnt_tsv_entete);
222
		$this->ecrireFichier($fichier_chemin, $bdnt_tsv_entete);
222
			
223
			
223
		foreach ($this->noms as $id => &$nom) {
224
		foreach ($this->noms as $id => &$nom) {
224
			$infos = array();
225
			$infos = array();
225
			foreach ($this->champs_ordre as $champ => $ordre) {
226
			foreach ($this->champs_ordre as $champ => $ordre) {
226
				if (array_key_exists($champ, $nom)) {
227
				if (array_key_exists($champ, $nom)) {
227
					$infos[$champ] = trim($nom[$champ]);
228
					$infos[$champ] = trim($nom[$champ]);
228
				} else {
229
				} else {
229
					$e = "Le champ '$champ' n'a pas été trouvé dans les données du nom : $id.";
230
					$e = "Le champ '$champ' n'a pas été trouvé dans les données du nom : $id.";
230
					$this->ajouterMessage($e);
231
					$this->ajouterMessage($e);
231
				}
232
				}
232
			}
233
			}
233
			$infos = $this->remplacerTabulation($infos);
234
			$infos = $this->remplacerTabulation($infos);
234
			$infos = $this->remplacerSautsDeLigne($infos);
235
			$infos = $this->remplacerSautsDeLigne($infos);
235
			$this->noms[$id] = $infos;
236
			$this->noms[$id] = $infos;
236
			
237
			
237
			$bdnt_tsv_ligne = $this->getVue('versionnage/squelettes/bdnt_ligne', array('nom_infos' => $infos), '.tpl.tsv');
238
			$bdnt_tsv_ligne = $this->getVue('versionnage/squelettes/bdnt_ligne', array('nom_infos' => $infos), '.tpl.tsv');
238
			$this->ajouterAuFichier($fichier_chemin, $bdnt_tsv_ligne);
239
			$this->ajouterAuFichier($fichier_chemin, $bdnt_tsv_ligne);
239
		}
240
		}
240
		$this->ecrireComplementFichierBdnt($fichier_chemin);
241
		$this->ecrireComplementFichierBdnt($fichier_chemin);
241
		return $donnees;
242
		return $donnees;
242
	}
243
	}
243
	
244
	
244
	private function determinerOrdreDesChamps() {
245
	private function determinerOrdreDesChamps() {
245
		$champs_ordre = explode(',', $this->manuel['champs']);
246
		$champs_ordre = explode(',', $this->manuel['champs']);
246
		$champs_ordre = array_flip($champs_ordre);
247
		$champs_ordre = array_flip($champs_ordre);
247
		$nom_courant = current($this->noms);
248
		$nom_courant = current($this->noms);
248
		$champs_ordre = $this->attribuerOrdreChampsSupplémentaires($champs_ordre, $nom_courant);
249
		$champs_ordre = $this->attribuerOrdreChampsSupplémentaires($champs_ordre, $nom_courant);
249
		asort($champs_ordre);
250
		asort($champs_ordre);
250
		$this->champs_ordre = $champs_ordre;
251
		$this->champs_ordre = $champs_ordre;
251
		Debug::printr("Ordre des champs : ".print_r($this->champs_ordre,true));
252
		Debug::printr("Ordre des champs : ".print_r($this->champs_ordre,true));
252
	}
253
	}
253
	
254
	
254
	private function attribuerOrdreChampsSupplémentaires($champs_ordre, $nom) {
255
	private function attribuerOrdreChampsSupplémentaires($champs_ordre, $nom) {
255
		foreach ($nom as $champ => $info) {
256
		foreach ($nom as $champ => $info) {
256
			if (!isset($champs_ordre[$champ])) {
257
			if (!isset($champs_ordre[$champ])) {
257
				$champs_ordre[$champ] = count($champs_ordre);
258
				$champs_ordre[$champ] = count($champs_ordre);
258
			}
259
			}
259
		}
260
		}
260
		return $champs_ordre;
261
		return $champs_ordre;
261
	}
262
	}
262
	
263
	
263
	private function definirNomDesChamps() {
264
	private function definirNomDesChamps() {
264
		$this->champs_nom = array_flip($this->champs_ordre);
265
		$this->champs_nom = array_flip($this->champs_ordre);
265
	}
266
	}
266
	
267
	
267
	private function definirNomDesChampsDiff() {
268
	private function definirNomDesChampsDiff() {
268
		$this->champs_diff = explode(',', $this->manuel['champs_diff']);
269
		$this->champs_diff = explode(',', $this->manuel['champs_diff']);
269
		$this->diff_champs_nom = array_merge($this->champs_nom, $this->champs_diff);
270
		$this->diff_champs_nom = array_merge($this->champs_nom, $this->champs_diff);
270
	}
271
	}
271
	
272
	
272
	private function ajouterMessage($message) {
273
	private function ajouterMessage($message) {
273
		$titre = self::SCRIPT_NOM.' #'.$this->traitement['id_traitement'];
274
		$titre = self::SCRIPT_NOM.' #'.$this->traitement['id_traitement'];
274
		$this->messages[] = array('message' => $message, 'resultat' => true);
275
		$this->messages[] = array('message' => $message, 'resultat' => true);
275
	}
276
	}
276
	
277
	
277
	private function remplacerTabulation($doc) {
278
	private function remplacerTabulation($doc) {
278
		if (is_string($doc)) {
279
		if (is_string($doc)) {
279
			$doc = str_replace("\t", ' ', $doc);
280
			$doc = str_replace("\t", ' ', $doc);
280
		} else if (is_array($doc) && count($doc) > 0) {
281
		} else if (is_array($doc) && count($doc) > 0) {
281
			foreach ($doc as $cle => $valeur) {
282
			foreach ($doc as $cle => $valeur) {
282
				$doc[$cle] = $this->remplacerTabulation($valeur);
283
				$doc[$cle] = $this->remplacerTabulation($valeur);
283
			}
284
			}
284
		}
285
		}
285
		return $doc;
286
		return $doc;
286
	}
287
	}
287
	
288
	
288
	private function remplacerSautsDeLigne($doc) {
289
	private function remplacerSautsDeLigne($doc) {
289
		if (is_string($doc)) {
290
		if (is_string($doc)) {
290
			$a_remplacer = array("\r", "\n");
291
			$a_remplacer = array("\r", "\n");
291
			$doc = str_replace($a_remplacer, ' ', $doc);
292
			$doc = str_replace($a_remplacer, ' ', $doc);
292
		} else if (is_array($doc) && count($doc) > 0) {
293
		} else if (is_array($doc) && count($doc) > 0) {
293
			foreach ($doc as $cle => $valeur) {
294
			foreach ($doc as $cle => $valeur) {
294
				$doc[$cle] = $this->remplacerSautsDeLigne($valeur);
295
				$doc[$cle] = $this->remplacerSautsDeLigne($valeur);
295
			}
296
			}
296
		}
297
		}
297
		return $doc;
298
		return $doc;
298
	}
299
	}
299
	
300
	
300
	private function ecrireComplementFichierBdnt($fichier_chemin) {
301
	private function ecrireComplementFichierBdnt($fichier_chemin) {
301
		if (file_exists($fichier_chemin)) {
302
		if (file_exists($fichier_chemin)) {
302
			$this->ajouterMessage("Écriture du fichier bdnt réussie.");
303
			$this->ajouterMessage("Écriture du fichier bdnt réussie.");
303
			$this->signature_md5 = md5_file($fichier_chemin);
304
			$this->signature_md5 = md5_file($fichier_chemin);
304
			$this->ajouterMessage("Signature MD5 du fichier bdnt :".$this->signature_md5);
305
			$this->ajouterMessage("Signature MD5 du fichier bdnt :".$this->signature_md5);
305
			$this->ajouterMessage("Nombre de combinaisons traitées : ".$this->noms_stat['combinaison']);
306
			$this->ajouterMessage("Nombre de combinaisons traitées : ".$this->noms_stat['combinaison']);
306
		}
307
		}
307
	}
308
	}
308
	
309
	
309
	private function getBaseNomFichier() {
310
	private function getBaseNomFichier() {
310
		return strtolower($this->meta['acronyme'].'_v'.str_replace('.', '_', $this->meta['version']));
311
		return strtolower($this->meta['acronyme'].'_v'.str_replace('.', '_', $this->meta['version']));
311
	}
312
	}
312
		
313
		
313
	private function creerFichierBdntPartiel(&$donnees) {
314
	private function creerFichierBdntPartiel(&$donnees) {
314
		$this->definirChampsPartiel();
315
		$this->definirChampsPartiel();
315
		Debug::printr(current($donnees['noms']));
316
		Debug::printr(current($donnees['noms']));
316
		$donnees['champs_partiel'] = $this->champs_nom_partiel;
317
		$donnees['champs_partiel'] = $this->champs_nom_partiel;
317
		$donnees['dernier_champ'] = end($this->champs_nom_partiel);
318
		$donnees['dernier_champ'] = end($this->champs_nom_partiel);
318
		$this->ecrireFichierBdntPartielle($donnees);
319
		$this->ecrireFichierBdntPartielle($donnees);
319
	}
320
	}
320
	
321
	
321
	private function definirChampsPartiel() {
322
	private function definirChampsPartiel() {
322
		$this->champs_nom_partiel = explode(',', $this->manuel['champs_partiel']);
323
		$this->champs_nom_partiel = explode(',', $this->manuel['champs_partiel']);
323
		Debug::printr("Champs partiels : ".print_r($this->champs_nom_partiel,true));
324
		Debug::printr("Champs partiels : ".print_r($this->champs_nom_partiel,true));
324
	}
325
	}
325
	
326
	
326
	private function ecrireFichierBdntPartielle(&$donnees) {
327
	private function ecrireFichierBdntPartielle(&$donnees) {
327
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_bdnt'];
328
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_bdnt'];
328
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
329
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
329
		$bdnt_tsv_entete = $this->getVue('versionnage/squelettes/bdnt_partiel_entete', array('champs_partiel' => $donnees['champs_partiel']), '.tpl.tsv');
330
		$bdnt_tsv_entete = $this->getVue('versionnage/squelettes/bdnt_partiel_entete', array('champs_partiel' => $donnees['champs_partiel']), '.tpl.tsv');
330
		$this->ecrireFichier($fichier_chemin, $bdnt_tsv_entete);
331
		$this->ecrireFichier($fichier_chemin, $bdnt_tsv_entete);
331
			
332
			
332
		foreach ($this->noms as $id => &$nom) {
333
		foreach ($this->noms as $id => &$nom) {
333
			$donnees['nom_infos'] = $nom;
334
			$donnees['nom_infos'] = $nom;
334
			$bdnt_tsv_ligne = $this->getVue('versionnage/squelettes/bdnt_partiel_ligne', $donnees, '.tpl.tsv');
335
			$bdnt_tsv_ligne = $this->getVue('versionnage/squelettes/bdnt_partiel_ligne', $donnees, '.tpl.tsv');
335
			if ($bdnt_tsv_ligne != '') {
336
			if ($bdnt_tsv_ligne != '') {
336
				$this->ajouterAuFichier($fichier_chemin, $bdnt_tsv_ligne);
337
				$this->ajouterAuFichier($fichier_chemin, $bdnt_tsv_ligne);
337
			}
338
			}
338
		}
339
		}
339
		
340
		
340
		if (file_exists($fichier_chemin)) {
341
		if (file_exists($fichier_chemin)) {
341
			$this->ajouterMessage("Écriture du fichier de la bdnt partielle réussie.");
342
			$this->ajouterMessage("Écriture du fichier de la bdnt partielle réussie.");
342
			$this->signature_md5_partiel = md5_file($fichier_chemin);
343
			$this->signature_md5_partiel = md5_file($fichier_chemin);
343
			$this->ajouterMessage("Signature MD5 du fichier bdnt partiel :".$this->signature_md5_partiel);
344
			$this->ajouterMessage("Signature MD5 du fichier bdnt partiel :".$this->signature_md5_partiel);
344
			$this->ajouterMessage("Nombre de combinaisons traitées : ".$this->noms_stat['combinaison']);
345
			$this->ajouterMessage("Nombre de combinaisons traitées : ".$this->noms_stat['combinaison']);
345
		}
346
		}
346
	}
347
	}
347
	
348
	
348
	private function ecrireFichier($fichier_chemin, &$contenu) {
349
	private function ecrireFichier($fichier_chemin, &$contenu) {
349
		$retour = true;
350
		$retour = true;
350
		if (file_put_contents($fichier_chemin, $contenu) == false) {
351
		if (file_put_contents($fichier_chemin, $contenu) == false) {
351
			$e = "Une erreur est survenu lors de l'écriture du fichier : $fichier_chemin";
352
			$e = "Une erreur est survenu lors de l'écriture du fichier : $fichier_chemin";
352
			$this->ajouterMessage($e);
353
			$this->ajouterMessage($e);
353
			$retour = false;
354
			$retour = false;
354
		}
355
		}
355
		$contenu = null;
356
		$contenu = null;
356
		return $retour;
357
		return $retour;
357
	}
358
	}
358
	
359
	
359
	private function ajouterAuFichier($fichier_chemin, &$contenu) {
360
	private function ajouterAuFichier($fichier_chemin, &$contenu) {
360
		$retour = true;
361
		$retour = true;
361
		if (file_put_contents($fichier_chemin, $contenu, FILE_APPEND) == false) {
362
		if (file_put_contents($fichier_chemin, $contenu, FILE_APPEND) == false) {
362
			$e = "Une erreur est survenu lors de l'ajout de données dans le fichier : $fichier_chemin";
363
			$e = "Une erreur est survenu lors de l'ajout de données dans le fichier : $fichier_chemin";
363
			$this->ajouterMessage($e);
364
			$this->ajouterMessage($e);
364
			$retour = false;
365
			$retour = false;
365
		}
366
		}
366
		$contenu = null;
367
		$contenu = null;
367
		return $retour;
368
		return $retour;
368
	}	
369
	}	
369
	
370
	
370
	private function creerFichierDiff() {
371
	private function creerFichierDiff() {
371
		$donnees = array();
372
		$donnees = array();
372
		$derniere_meta = $this->metaDao->getDerniere($this->projet);
373
		$derniere_meta = $this->metaDao->getDerniere($this->projet);
373
		if (is_null($derniere_meta === false)) {
374
		if (is_null($derniere_meta === false)) {
374
			$this->ajouterMessage("Un problème est survenu lors de la récupération des métadonnées précédentes.");
375
			$this->ajouterMessage("Un problème est survenu lors de la récupération des métadonnées précédentes.");
375
		} else if (is_null($derniere_meta)) {
376
		} else if (is_null($derniere_meta)) {
376
			$this->ajouterMessage("Premier versionnage pour ce projet, aucun fichier différentiel ne sera créé.");
377
			$this->ajouterMessage("Premier versionnage pour ce projet, aucun fichier différentiel ne sera créé.");
377
		} else {
378
		} else {
378
			$code_projet_precedent = strtolower($derniere_meta['code']).'_v'.str_replace('.', '_', $derniere_meta['version']);
379
			$code_projet_precedent = strtolower($derniere_meta['code']).'_v'.str_replace('.', '_', $derniere_meta['version']);
379
			if ($code_projet_precedent == $this->version_courante) {
380
			if ($code_projet_precedent == $this->version_courante) {
380
				$e = "La code de la version préalablement versionnée ($code_projet_precedent) est le même que celui ".
381
				$e = "La code de la version préalablement versionnée ($code_projet_precedent) est le même que celui ".
381
					"de la demande actuel ({$this->version_courante}) pour ce projet, aucun fichier différentiel ne sera créé.";
382
					"de la demande actuel ({$this->version_courante}) pour ce projet, aucun fichier différentiel ne sera créé.";
382
				$this->ajouterMessage($e);
383
				$this->ajouterMessage($e);
383
			} else {
384
			} else {
384
				$this->noms_precedents = $this->referentielDao->getTout($code_projet_precedent);
385
				$this->noms_precedents = $this->referentielDao->getTout($code_projet_precedent);
385
				$donnees['diff'] = $this->realiserDiff();
386
				$donnees['diff'] = $this->realiserDiff();
386
				$donnees['champs'] = $this->diff_champs_nom;
387
				$donnees['champs'] = $this->diff_champs_nom;
387
				$diff_tsv =& $this->getVue('versionnage/squelettes/diff', &$donnees, '.tpl.tsv');
388
				$diff_tsv =& $this->getVue('versionnage/squelettes/diff', &$donnees, '.tpl.tsv');
388
				$this->ecrireFichierDiff($diff_tsv);
389
				$this->ecrireFichierDiff($diff_tsv);
389
			}
390
			}
390
		}
391
		}
391
		return $donnees;
392
		return $donnees;
392
	}
393
	}
393
	
394
	
394
	private function realiserDiff() {
395
	private function realiserDiff() {
395
		$this->chargerTableauChampsModifTypes();
396
		$this->chargerTableauChampsModifTypes();
396
		$this->noms_stat['modification'] = 0;
397
		$this->noms_stat['modification'] = 0;
-
 
398
		
-
 
399
		$this->verifierNomsSupprimes();
397
		
400
		$this->champs_courants = $this->champs_nom; 
398
		$diff = array();
-
 
399
		$i = 0;
401
		$diff = array();
-
 
402
		foreach ($this->noms as $id => $nom) {
400
		foreach ($this->noms as $id => $nom) {
403
			if ($this->noms[$id]['exclure_taxref'] == '1') {
-
 
404
				unset($this->noms[$id]);
-
 
405
			} else {
-
 
406
				foreach ($this->noms[$id] as $champ => $valeur) {
-
 
407
					if (! in_array($champ, $this->champs_nom_partiel)) {
-
 
408
						unset($this->noms[$id][$champ]);
-
 
409
					}
-
 
410
				}
401
			$this->noms[$id] = null;
411
			}
-
 
412
			$infos = array();
-
 
413
			if (isset($this->noms_supprimes[$id])) {
402
			$infos = array();
414
					$infos = $this->traiterDiffSuppression($nom);
403
			if (!isset($this->noms_precedents[$id])) {
415
			} else if (!isset($this->noms_precedents[$id])) {
404
				$infos = $this->traiterDiffAjout($nom);
416
				$infos = $this->traiterDiffAjout($nom);
405
			} else {
417
			} else {
406
				$nom_precedent = $this->noms_precedents[$id];
418
				$nom_precedent = $this->noms_precedents[$id];
-
 
419
				if ($this->noms_precedents[$id]['exclure_taxref'] == '1') {
407
				unset($this->noms_precedents[$id]);
420
					unset($this->noms_precedents[$id]);
-
 
421
				} else {
-
 
422
					foreach ($this->noms_precedents[$id] as $champ => $valeur) {
-
 
423
						if (! in_array($champ, $this->champs_nom_partiel)) {
-
 
424
							unset($this->noms_precedents[$id][$champ]);
-
 
425
						}
-
 
426
					}
-
 
427
				}
408
				array_walk($nom_precedent, create_function('&$val', '$val = trim($val);')); 
428
				array_walk($nom_precedent, create_function('&$val', '$val = trim($val);')); 
409
				$infos = $this->traiterDiffModif($nom, $nom_precedent);
429
				$infos = $this->traiterDiffModif($nom, $nom_precedent);
410
			}
430
			}
411
			if ($nom['exclure_taxref'] == '1') {
-
 
412
				$this->exclure_taxref[] = $id;
-
 
413
			}
-
 
414
			
431
			
-
 
432
			if (count($infos) > 0) {
415
			if (count($infos) > 0) {
433
				$this->noms_stat['modification']++;
416
				$infos = $this->remplacerTabulation($infos);
434
				$infos = $this->remplacerTabulation($infos);
417
				$infos = $this->remplacerSautsDeLigne($infos);
435
				$infos = $this->remplacerSautsDeLigne($infos);
418
				$diff[$id] = $infos;
436
				$diff[$id] = $infos;
419
			}
437
			}
420
		}
438
		}
421
		$this->verifierLignesSupprimees();
-
 
422
		
439
		
423
		return $diff;
440
		return $diff;
424
	}
441
	}
425
	
442
	
-
 
443
	private function verifierNomsSupprimes($edition = '«Complète»') {
426
	private function verifierLignesSupprimees() {
444
		$this->noms_supprimes = array_diff_key($this->noms, $this->noms_precedents);
427
		$e = count($this->noms_precedents)." lignes ont été supprimées vis à vis de la version ".
445
		$e = count($this->noms_supprimes)." lignes ont été supprimées vis à vis de la version ".
-
 
446
			"précédentes pour l'édition $edition. Cela concerne les noms : ".implode(', ', array_keys($this->noms_supprimes));
428
			"précédentes. Cela concerne les noms : ".implode(', ', array_keys($this->noms_precedents));
447
		Debug::printr($e);
429
		$this->ajouterMessage($e);
448
		$this->ajouterMessage($e);
430
	} 
449
	} 
-
 
450
	
-
 
451
	private function traiterDiffSuppression(&$nom) {
-
 
452
		$infos = $nom;
-
 
453
		$infos['modification_type'] = 'S';
-
 
454
		$infos['modification_type_1'] = '0';
-
 
455
		$infos['modification_type_2'] = '0';
-
 
456
		$infos['modification_type_3'] = '0';
-
 
457
		return $infos;
-
 
458
	}
431
	
459
	
432
	private function traiterDiffAjout(&$nom) {
460
	private function traiterDiffAjout(&$nom) {
433
		$infos = $nom;
461
		$infos = $nom;
434
		$infos['modification_type'] = 'A';
462
		$infos['modification_type'] = 'A';
435
		$infos['modification_type_1'] = '0';
463
		$infos['modification_type_1'] = '0';
436
		$infos['modification_type_2'] = '0';
464
		$infos['modification_type_2'] = '0';
437
		$infos['modification_type_3'] = '0';
465
		$infos['modification_type_3'] = '0';
438
		$this->noms_stat['modification']++;
-
 
439
		return $infos;
466
		return $infos;
440
	}
467
	}
441
	
468
	
442
	private function traiterDiffModif(&$nom, &$nom_precedent) {
469
	private function traiterDiffModif(&$nom, &$nom_precedent) {
443
		$infos = array();
470
		$infos = array();
444
		$nom_diff = array_diff_assoc($nom, $nom_precedent);
471
		$nom_diff = array_diff_assoc($nom, $nom_precedent);
445
		
472
		
446
		if (count($nom_diff) > 0) {
473
		if (count($nom_diff) > 0) {
447
			$modif['modification_type'] = 'M';
474
			$modif['modification_type'] = 'M';
448
			$modif['modification_type_1'] = '0';
475
			$modif['modification_type_1'] = '0';
449
			$modif['modification_type_2'] = '0';
476
			$modif['modification_type_2'] = '0';
450
			$modif['modification_type_3'] = '0';
477
			$modif['modification_type_3'] = '0';
451
			
478
			
452
			foreach ($this->champs_nom as $champ) {
479
			foreach ($this->champs_courants as $champ) {
453
				if (isset($nom_diff[$champ])) {
480
				if (isset($nom_diff[$champ])) {
454
					// Si le champ modifié est vide nous retournons le mot clé "NULL" pour identifier le champ modifié
481
					// Si le champ modifié est vide nous retournons le mot clé "NULL" pour identifier le champ modifié
455
					$infos[$champ] = ($nom_diff[$champ] != '') ? $nom_diff[$champ] : 'NULL';
482
					$infos[$champ] = ($nom_diff[$champ] != '') ? $nom_diff[$champ] : 'NULL';
456
					$type = $this->getDiffType($champ);
483
					$type = $this->getDiffType($champ);
457
					$modif['modification_type_'.$type] = '1';
484
					$modif['modification_type_'.$type] = '1';
458
				} else {
485
				} else {
459
					if ($champ == 'num_nom') {
486
					if ($champ == 'num_nom') {
460
						$infos[$champ] = $nom[$champ];
487
						$infos[$champ] = $nom[$champ];
461
					} else {
488
					} else {
462
						$infos[$champ] = '';
489
						$infos[$champ] = '';
463
					}
490
					}
464
				}
491
				}
465
			}
492
			}
466
			
493
			
467
			foreach ($modif as $cle => $val) {
494
			foreach ($modif as $cle => $val) {
468
				$infos[$cle] = $val;
495
				$infos[$cle] = $val;
469
			}
496
			}
470
			
-
 
471
			$this->noms_stat['modification']++;
-
 
472
		}
497
		}
473
		return $infos;
498
		return $infos;
474
	}
499
	}
475
	
500
	
476
	private function chargerTableauChampsModifTypes() {
501
	private function chargerTableauChampsModifTypes() {
477
		$champs = explode(',', $this->manuel['champs_diff_type']);
502
		$champs = explode(',', $this->manuel['champs_diff_type']);
478
		foreach ($champs as $champ) {
503
		foreach ($champs as $champ) {
479
			list($champ_nom, $type) = explode('=', trim($champ));
504
			list($champ_nom, $type) = explode('=', trim($champ));
480
			$this->diff_modif_types[$champ_nom] = $type;
505
			$this->diff_modif_types[$champ_nom] = $type;
481
		}
506
		}
482
	}
507
	}
483
	
508
	
484
	private function getDiffType($champ_nom) {
509
	private function getDiffType($champ_nom) {
485
		$type = isset($this->diff_modif_types[$champ_nom]) ? $this->diff_modif_types[$champ_nom] : '3';
510
		$type = isset($this->diff_modif_types[$champ_nom]) ? $this->diff_modif_types[$champ_nom] : '3';
486
		return $type;
511
		return $type;
487
	}
512
	}
488
	
513
	
489
	private function ecrireFichierDiff(&$contenu) {
514
	private function ecrireFichierDiff(&$contenu) {
490
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_diff'];
515
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_diff'];
491
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
516
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
492
		
517
		
493
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
518
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
494
			$this->ajouterMessage("Écriture du fichier diff réussie.");
519
			$this->ajouterMessage("Écriture du fichier diff réussie.");
495
		}
520
		}
496
	}
521
	}
497
	
522
	
498
	private function creerFichierDiffPartiel(&$donnees) {
523
	private function creerFichierDiffPartiel(&$donnees) {
499
		$this->noms_stat_partiel['modification'] = 0;
524
		$this->noms_stat_partiel['modification'] = 0;
500
		if (count($donnees) > 0 && count($donnees['diff']) > 0) {
525
		if (! is_null($derniere_meta) && $derniere_meta !== false) {
501
			foreach ($donnees['diff'] as $id => $nom) {
-
 
502
				if (!in_array($id, $this->exclure_taxref)) {
-
 
503
					if ($nom['modification_type'] == 'A') {
-
 
504
						$donnees['diff_partiel'][$id] = $nom;
526
			$donnees['diff_partiel'] = $this->realiserDiff();
505
					} else {
-
 
506
						foreach ($nom as $champ => $valeur) {
-
 
507
							$ok = false;
-
 
508
							if ($valeur != '' && $champ != 'num_nom' && in_array($champ, $this->champs_nom_partiel)) {
-
 
509
								$donnees['diff_partiel'][$id] = $nom;
-
 
510
								Debug::printr($id.":".$champ."/".$valeur);
-
 
511
								break;
-
 
512
							}
-
 
513
						}
-
 
514
					}
-
 
515
					if (array_key_exists($id, $donnees['diff_partiel'])) {
-
 
516
						$this->noms_stat_partiel['modification']++;
-
 
517
					}
-
 
518
				}
-
 
519
				unset($donnees['diff'][$id]);
-
 
520
			}
-
 
521
			$donnees['champs_partiel_diff'] = array_merge($this->champs_nom_partiel, $this->champs_diff);
527
			$donnees['champs_partiel_diff'] = array_merge($this->champs_nom_partiel, $this->champs_diff);
522
			$donnees['dernier_champ'] = end($donnees['champs_partiel_diff']);
528
			$donnees['dernier_champ'] = end($donnees['champs_partiel_diff']);
523
			$diff_tsv_partiel =& $this->getVue('versionnage/squelettes/diff_partiel', &$donnees, '.tpl.tsv');
529
			$diff_tsv_partiel =& $this->getVue('versionnage/squelettes/diff_partiel', &$donnees, '.tpl.tsv');
524
			$this->ecrireFichierDiffPartiel($diff_tsv_partiel);
530
			$this->ecrireFichierDiffPartiel($diff_tsv_partiel);
525
		}
531
		}
526
	}
532
	}
-
 
533
	
-
 
534
	private function realiserDiffPartiel() {
-
 
535
		$this->noms_stat_partiel['modification'] = 0;
-
 
536
		
-
 
537
		$this->champs_courants = $this->champs_nom_partiel;
-
 
538
		$this->verifierNomsSupprimes('«Partielle»');
-
 
539
		$diff = array();
-
 
540
		foreach ($this->noms as $id => $nom) {
-
 
541
			unset($this->noms[$id]);
-
 
542
			$infos = array();
-
 
543
			if (isset($this->noms_supprimes[$id])) {
-
 
544
				$infos = $this->traiterDiffSuppression($nom);
-
 
545
			} else if (!isset($this->noms_precedents[$id])) {
-
 
546
				$infos = $this->traiterDiffAjout($nom);
-
 
547
			} else {
-
 
548
				$nom_precedent = $this->noms_precedents[$id];
-
 
549
				unset($this->noms_precedents[$id]);
-
 
550
				array_walk($nom_precedent, create_function('&$val', '$val = trim($val);')); 
-
 
551
				$infos = $this->traiterDiffModif($nom, $nom_precedent);
-
 
552
			}
-
 
553
			
-
 
554
			if (count($infos) > 0) {
-
 
555
				$this->noms_stat_partiel['modification']++;
-
 
556
				$infos = $this->remplacerTabulation($infos);
-
 
557
				$infos = $this->remplacerSautsDeLigne($infos);
-
 
558
				$diff[$id] = $infos;
-
 
559
			}
-
 
560
		}
-
 
561
		
-
 
562
		return $diff;
-
 
563
	}
527
	
564
	
528
	private function ecrireFichierDiffPartiel(&$contenu) {
565
	private function ecrireFichierDiffPartiel(&$contenu) {
529
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_diff'];
566
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_diff'];
530
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
567
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
531
		
568
		
532
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
569
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
533
			$this->ajouterMessage("Écriture du fichier diff partiel réussie.");
570
			$this->ajouterMessage("Écriture du fichier diff partiel réussie.");
534
		}
571
		}
535
	}
572
	}
536
	
573
	
537
	private function creerFichierMeta() {
574
	private function creerFichierMeta() {
538
		$donnees = array();
575
		$donnees = array();
539
		$donnees = $this->meta;
576
		$donnees = $this->meta;
540
		$donnees['stats'] = $this->noms_stat;
577
		$donnees['stats'] = $this->noms_stat;
541
		$donnees['signature'] = $this->signature_md5;
578
		$donnees['signature'] = $this->signature_md5;
542
		
579
		
543
		$donnees = $this->remplacerTabulation($donnees);
580
		$donnees = $this->remplacerTabulation($donnees);
544
		$donnees = $this->remplacerSautsDeLigne($donnees);
581
		$donnees = $this->remplacerSautsDeLigne($donnees);
545
		
582
		
546
		$meta_tsv =& $this->getVue('versionnage/squelettes/meta', &$donnees, '.tpl.tsv');
583
		$meta_tsv =& $this->getVue('versionnage/squelettes/meta', &$donnees, '.tpl.tsv');
547
		$this->ecrireFichierMeta($meta_tsv);
584
		$this->ecrireFichierMeta($meta_tsv);
548
		return $donnees;
585
		return $donnees;
549
	}
586
	}
550
	
587
	
551
	private function ecrireFichierMeta(&$contenu) {
588
	private function ecrireFichierMeta(&$contenu) {
552
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_meta'];
589
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_meta'];
553
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
590
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
554
		
591
		
555
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
592
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
556
			$this->ajouterMessage("Écriture du fichier meta réussie.");
593
			$this->ajouterMessage("Écriture du fichier meta réussie.");
557
			$this->archiverMetadonnees();
594
			$this->archiverMetadonnees();
558
		}
595
		}
559
	}
596
	}
560
	
597
	
561
	private function creerFichierMetaPartiel(&$donnees) {
598
	private function creerFichierMetaPartiel(&$donnees) {
562
		$donnees['signature'] = $this->signature_md5_partiel;
599
		$donnees['signature'] = $this->signature_md5_partiel;
563
		$donnees['stats'] = $this->noms_stat_partiel;
600
		$donnees['stats'] = $this->noms_stat_partiel;
564
		$donnees['notes'] = trim('Édition partielle. '.$donnees['notes']);
601
		$donnees['notes'] = trim('Édition partielle. '.$donnees['notes']);
565
		$meta_tsv_partiel =& $this->getVue('versionnage/squelettes/meta', &$donnees, '.tpl.tsv');
602
		$meta_tsv_partiel =& $this->getVue('versionnage/squelettes/meta', &$donnees, '.tpl.tsv');
566
		$this->ecrireFichierMetaPartiel($meta_tsv_partiel);
603
		$this->ecrireFichierMetaPartiel($meta_tsv_partiel);
567
	}
604
	}
568
	
605
	
569
	private function ecrireFichierMetaPartiel(&$contenu) {
606
	private function ecrireFichierMetaPartiel(&$contenu) {
570
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_meta'];
607
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_meta'];
571
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
608
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
572
		
609
		
573
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
610
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
574
			$this->ajouterMessage("Écriture du fichier meta partiel réussie.");
611
			$this->ajouterMessage("Écriture du fichier meta partiel réussie.");
575
		}
612
		}
576
	}
613
	}
577
	
614
	
578
	private function archiverMetadonnees() {
615
	private function archiverMetadonnees() {
579
		$metadonnees = $this->meta;
616
		$metadonnees = $this->meta;
580
		$metadonnees['code'] = $this->meta['acronyme'];
617
		$metadonnees['code'] = $this->meta['acronyme'];
581
		unset($metadonnees['acronyme']);
618
		unset($metadonnees['acronyme']);
582
		$metadonnees['domaine_taxo'] = $this->meta['dom_tax'];
619
		$metadonnees['domaine_taxo'] = $this->meta['dom_tax'];
583
		unset($metadonnees['dom_tax']);
620
		unset($metadonnees['dom_tax']);
584
		$metadonnees['domaine_geo'] = $this->meta['dom_geo'];
621
		$metadonnees['domaine_geo'] = $this->meta['dom_geo'];
585
		unset($metadonnees['dom_geo']);
622
		unset($metadonnees['dom_geo']);
586
		$metadonnees['domaine_nom'] = $this->meta['dom_code'];
623
		$metadonnees['domaine_nom'] = $this->meta['dom_code'];
587
		unset($metadonnees['dom_code']);
624
		unset($metadonnees['dom_code']);
588
		$metadonnees['auteur'] = $this->meta['auteur_principal'];
625
		$metadonnees['auteur'] = $this->meta['auteur_principal'];
589
		unset($metadonnees['auteur_principal']);
626
		unset($metadonnees['auteur_principal']);
590
		$metadonnees['date_production'] = $this->meta['date_prod'];
627
		$metadonnees['date_production'] = $this->meta['date_prod'];
591
		unset($metadonnees['date_prod']);
628
		unset($metadonnees['date_prod']);
592
		$metadonnees['droit'] = $this->meta['copyright'];
629
		$metadonnees['droit'] = $this->meta['copyright'];
593
		unset($metadonnees['copyright']);
630
		unset($metadonnees['copyright']);
594
		
631
		
595
		$ok = $this->metaDao->ajouter($metadonnees);
632
		$ok = $this->metaDao->ajouter($metadonnees);
596
		if ($ok === false) {
633
		if ($ok === false) {
597
			$this->ajouterMessage("L'archivage des métadonnées a échoué.");
634
			$this->ajouterMessage("L'archivage des métadonnées a échoué.");
598
		}
635
		}
599
	}
636
	}
600
	
637
	
601
	private function nettoyerMemoire() {
638
	private function nettoyerMemoire() {
602
		$this->noms = null;
639
		$this->noms = null;
603
		$this->noms_precedents = null;
640
		$this->noms_precedents = null;
604
		$this->noms_stat = null; 
641
		$this->noms_stat = null; 
605
	}
642
	}
606
	
643
	
607
	private function copierManuel() {
644
	private function copierManuel() {
608
		$fichier_source = $this->manuel_chemin.$this->manuel_nom;
645
		$fichier_source = $this->manuel_chemin.$this->manuel_nom;
609
		$fichiers_destination[] = $this->zip_chemin_dossier.$this->manuel_nom;
646
		$fichiers_destination[] = $this->zip_chemin_dossier.$this->manuel_nom;
610
		$fichiers_destination[] = $this->zip_chemin_dossier_partiel.$this->manuel_nom;
647
		$fichiers_destination[] = $this->zip_chemin_dossier_partiel.$this->manuel_nom;
611
		foreach ($fichiers_destination as $destination) {
648
		foreach ($fichiers_destination as $destination) {
612
			if (copy($fichier_source, $destination) === false) {
649
			if (copy($fichier_source, $destination) === false) {
613
				$this->ajouterMessage("La copie du manuel vers '$destination' a échouée.");
650
				$this->ajouterMessage("La copie du manuel vers '$destination' a échouée.");
614
			}
651
			}
615
		}
652
		}
616
	}
653
	}
617
	
654
	
618
	private function creerFichiersZip() {
655
	private function creerFichiersZip() {
619
		$this->zipper($this->zip_chemin_fichier, $this->zip_chemin_dossier);
656
		$this->zipper($this->zip_chemin_fichier, $this->zip_chemin_dossier);
620
		$this->zipper($this->zip_chemin_fichier_partiel, $this->zip_chemin_dossier_partiel);
657
		$this->zipper($this->zip_chemin_fichier_partiel, $this->zip_chemin_dossier_partiel);
621
	}
658
	}
622
	
659
	
623
	private function zipper($fichier_zip, $dossier_a_zipper) {
660
	private function zipper($fichier_zip, $dossier_a_zipper) {
624
		$zip = new PclZip($fichier_zip);
661
		$zip = new PclZip($fichier_zip);
625
		if ($zip->add($dossier_a_zipper, PCLZIP_OPT_REMOVE_ALL_PATH) == 0) {
662
		if ($zip->add($dossier_a_zipper, PCLZIP_OPT_REMOVE_ALL_PATH) == 0) {
626
			$e = "La création du fichier zip '$fichier_zip' a échoué avec l'erreur : ".$zip->errorInfo(true);
663
			$e = "La création du fichier zip '$fichier_zip' a échoué avec l'erreur : ".$zip->errorInfo(true);
627
			$this->ajouterMessage($e);
664
			$this->ajouterMessage($e);
628
		}
665
		}
629
	}
666
	}
630
	
667
	
631
	private function nettoyerFichiers() {
668
	private function nettoyerFichiers() {
632
		Fichier::supprimerDossier($this->zip_chemin_dossier);
669
		Fichier::supprimerDossier($this->zip_chemin_dossier);
633
		Fichier::supprimerDossier($this->zip_chemin_dossier_partiel);
670
		Fichier::supprimerDossier($this->zip_chemin_dossier_partiel);
634
	}
671
	}
635
	
672
	
636
	private function traiterMessages() {
673
	private function traiterMessages() {
637
		if (isset($this->messages)) {
674
		if (isset($this->messages)) {
638
			$num_message = 1;
675
			$num_message = 1;
639
			foreach ($this->messages as $message) {
676
			foreach ($this->messages as $message) {
640
				$message['nom'] = 'Message #'.$num_message++;
677
				$message['nom'] = 'Message #'.$num_message++;
641
				$this->resultatDao->ajouter($this->traitement['id_traitement'], $message);
678
				$this->resultatDao->ajouter($this->traitement['id_traitement'], $message);
642
			}
679
			}
643
		}
680
		}
644
	}
681
	}
645
}
682
}
646
?>
683
?>