Subversion Repositories Applications.referentiel

Rev

Rev 58 | Rev 138 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 58 Rev 65
Line 29... Line 29...
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;
-
 
35
	private $zip_chemin_fichier_partiel = null;
Line 34... Line 36...
34
	
36
	
35
	private $noms = null;
37
	private $noms = null;
36
	private $noms_precedents = null;
38
	private $noms_precedents = null;
37
	private $noms_stat = null;
39
	private $noms_stat = null;
38
	private $champs_ordre = null;
40
	private $champs_ordre = null;
-
 
41
	private $champs_nom = null;
-
 
42
	private $champs_nom_partiel = null;
-
 
43
	private $champs_diff = null;
39
	private $champs_nom = null;
44
	private $diff_champs_nom = null;
40
	private $diff_modif_types = null;
45
	private $diff_modif_types = null;
-
 
46
	private $signature_md5 = null;
Line 41... Line 47...
41
	private $signature_md5 = null;
47
	private $signature_md5_partiel = null;
42
	
48
	
43
	private $resultatDao = null;
49
	private $resultatDao = null;
44
	private $traitementDao = null;
50
	private $traitementDao = null;
Line 94... Line 100...
94
	
100
	
95
    public function lancerVersionnage() {
101
    public function lancerVersionnage() {
96
		$this->chargerTraitementParametre();
102
		$this->chargerTraitementParametre();
97
		$this->initialiserNomVersionCOurante();
103
		$this->initialiserNomVersionCOurante();
98
		$this->initialiserCheminsZip();
104
		$this->initialiserCheminsZip();
99
		$this->creerDossierZip();
105
		$this->creerDossiersZip();
100
		$this->archiver();
106
		$this->archiver();
101
    	$this->chargerNomsATraiter();
107
    	$this->chargerNomsATraiter();
102
    	$this->analyserNomsATraiter();
108
    	$this->analyserNomsATraiter();
103
		$this->creerFichiers();
109
		$this->creerFichiers();
Line 126... Line 132...
126
	}
132
	}
Line 127... Line 133...
127
	
133
	
128
	private function initialiserCheminsZip() {
134
	private function initialiserCheminsZip() {
129
		$this->zip_chemin_dossier = Config::get('chemin_referentiel_zip').$this->version_courante.DIRECTORY_SEPARATOR;
135
		$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_dossier_partiel = Config::get('chemin_referentiel_zip').$this->version_courante.'_partiel'.DIRECTORY_SEPARATOR;
130
		$this->zip_chemin_fichier = Config::get('chemin_referentiel_zip').$this->version_courante.'.zip';
138
		$this->zip_chemin_fichier_partiel = Config::get('chemin_referentiel_zip').$this->version_courante.'_partiel.zip';
Line 131... Line 139...
131
	}
139
	}
132
	
140
	
133
	private function creerDossierZip() {
141
	private function creerDossiersZip() {
134
		$recursivite = true;
142
		$recursivite = true;
135
		if (mkdir($this->zip_chemin_dossier, 0777, $recursivite) === false) {
143
		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
		}
-
 
146
		if (mkdir($this->zip_chemin_dossier_partiel, 0777, $recursivite) === false) {
136
			$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier' devant contenir les fichiers a échouée.");
147
			$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier_partiel' devant contenir les fichiers partiels a échouée.");
Line 137... Line 148...
137
		}
148
		}
138
	}
149
	}
139
	
150
	
Line 161... Line 172...
161
		return $nbre;
172
		return $nbre;
162
	}
173
	}
Line 163... Line 174...
163
	
174
	
164
	private function creerFichiers() {
175
	private function creerFichiers() {
165
		// Respecter l'ordre de traitement : BDNT puis DIFF puis META
176
		// Respecter l'ordre de traitement : BDNT puis DIFF puis META
-
 
177
		$donnees =& $this->creerFichierBdnt();
-
 
178
		$this->creerFichierBdntPartiel($donnees);
166
		$this->creerFichierBdnt();
179
		$donnees = null;
-
 
180
		$donnees =& $this->creerFichierDiff();
-
 
181
		$this->creerFichierDiffPartiel($donnees);
167
		$this->creerFichierDiff();
182
		$donnees = null;
-
 
183
		$donnees =& $this->creerFichierMeta();
-
 
184
		$this->creerFichierMetaPartiel($donnees);
168
		$this->creerFichierMeta();
185
		$donnees = null;
169
		$this->nettoyerMemoire();
186
		$this->nettoyerMemoire();
170
		$this->copierManuel();
187
		$this->copierManuel();
171
		$this->creerFichierZip();
188
		$this->creerFichiersZip();
Line 172... Line 189...
172
	}
189
	}
173
	
-
 
174
	private function creerFichierBdnt() {
190
	
175
		$noms =& $this->noms;
191
	private function creerFichierBdnt() {
Line 176... Line 192...
176
		reset($this->noms);
192
		reset($this->noms);
177
		Debug::printr("Element courrant du tableau des noms : ".count($this->noms).'-'.print_r(current($this->noms),true));
193
		Debug::printr("Element courrant du tableau des noms : ".count($this->noms).'-'.print_r(current($this->noms),true));
-
 
194
		
Line 178... Line 195...
178
		
195
		$this->determinerOrdreDesChamps();
179
		$this->determinerOrdreDesChamps();
196
		$this->definirNomDesChamps();
180
		$this->definirNomDesChamps();
197
		$this->definirNomDesChampsDiff();
181
		
198
		
182
		$donnees = array();
199
		$donnees = array();
183
		$donnees['champs'] = $this->champs_nom;
200
		$donnees['champs'] = $this->champs_nom;
184
		foreach ($this->noms as &$nom) {
-
 
185
			$infos = array();
201
		foreach ($this->noms as $id => &$nom) {
186
			foreach ($nom as $champ => &$valeur) {
202
			$infos = array();
187
				if (isset($this->champs_ordre[$champ])) {
203
			foreach ($this->champs_ordre as $champ => $ordre) {
188
					$ordre = $this->champs_ordre[$champ];
204
				if (isset($nom[$champ])) {
189
					$infos[(int) $ordre] = trim($valeur);
205
					$infos[$champ] = trim($nom[$champ]);
190
				} else {
206
				} else {
191
					$e = "Le champ '$champ' n'a pas été pris en compte dans l'attribution de l'ordre des champs.";
207
					$e = "Le champ '$champ' n'a pas été trouvé dans les données du nom : $id.";
192
					$this->ajouterMessage($e);
208
					$this->ajouterMessage($e);
193
				}
209
				}
194
			}
210
			}
195
			ksort($infos);
211
			ksort($infos);
196
			$infos = $this->remplacerTabulation($infos);
212
			$infos = $this->remplacerTabulation($infos);
197
			$infos = $this->remplacerSautsDeLigne($infos);
213
			$infos = $this->remplacerSautsDeLigne($infos);
198
			$donnees['noms'][] = $infos;
214
			$donnees['noms'][$id] = $infos;
-
 
215
		}
199
		}
216
		Debug::printr("Dernier element du tableau des noms [trié] : ".print_r($infos,true));
Line 200... Line 217...
200
		Debug::printr("Dernier element du tableau des noms [trié] : ".print_r($infos,true));
217
		$bdnt_tsv =& $this->getVue('versionnage/squelettes/bdnt', &$donnees, '.tpl.tsv');
201
		$bdnt_tsv =& $this->getVue('versionnage/squelettes/bdnt', $donnees, '.tpl.tsv');
218
		$this->ecrireFichierBdnt($bdnt_tsv);
202
		$this->ecrireFichierBdnt($bdnt_tsv);
219
		return $donnees;
Line 210... Line 227...
210
		asort($champs_ordre);
227
		asort($champs_ordre);
211
		$this->champs_ordre = $champs_ordre;
228
		$this->champs_ordre = $champs_ordre;
212
		Debug::printr("Ordre des champs : ".print_r($this->champs_ordre,true));
229
		Debug::printr("Ordre des champs : ".print_r($this->champs_ordre,true));
213
	}
230
	}
Line 214... Line -...
214
	
-
 
215
	private function definirNomDesChamps() {
-
 
216
		$this->champs_nom = array_flip($this->champs_ordre);
-
 
217
	}
-
 
218
	
231
	
219
	private function attribuerOrdreChampsSupplémentaires($champs_ordre, $nom) {
232
	private function attribuerOrdreChampsSupplémentaires($champs_ordre, $nom) {
220
		foreach ($nom as $champ => $info) {
233
		foreach ($nom as $champ => $info) {
221
			if (!isset($champs_ordre[$champ])) {
234
			if (!isset($champs_ordre[$champ])) {
222
				$champs_ordre[$champ] = count($champs_ordre);
235
				$champs_ordre[$champ] = count($champs_ordre);
223
			}
236
			}
224
		}
237
		}
225
		return $champs_ordre;
238
		return $champs_ordre;
Line -... Line 239...
-
 
239
	}
-
 
240
	
-
 
241
	private function definirNomDesChamps() {
-
 
242
		$this->champs_nom = array_flip($this->champs_ordre);
-
 
243
	}
-
 
244
	
-
 
245
	private function definirNomDesChampsDiff() {
-
 
246
		$this->champs_diff = explode(',', $this->manuel['champs_diff']);
-
 
247
		$this->diff_champs_nom = array_merge($this->champs_nom, $this->champs_diff);
226
	}
248
	}
227
	
249
	
228
	private function ajouterMessage($message) {
250
	private function ajouterMessage($message) {
229
		$titre = self::SCRIPT_NOM.' #'.$this->traitement['id_traitement'];
251
		$titre = self::SCRIPT_NOM.' #'.$this->traitement['id_traitement'];
Line -... Line 252...
-
 
252
		$this->messages[] = array('message' => $message, 'resultat' => true);
-
 
253
	}
-
 
254
	
-
 
255
	private function remplacerTabulation($doc) {
-
 
256
		if (is_string($doc)) {
-
 
257
			$doc = str_replace("\t", ' ', $doc);
-
 
258
		} else if (is_array($doc) && count($doc) > 0) {
-
 
259
			foreach ($doc as $cle => $valeur) {
-
 
260
				$doc[$cle] = $this->remplacerTabulation($valeur);
-
 
261
			}
-
 
262
		}
-
 
263
		return $doc;
-
 
264
	}
-
 
265
	
-
 
266
	private function remplacerSautsDeLigne($doc) {
-
 
267
		if (is_string($doc)) {
-
 
268
			$a_remplacer = array("\r", "\n");
-
 
269
			$doc = str_replace($a_remplacer, ' ', $doc);
-
 
270
		} else if (is_array($doc) && count($doc) > 0) {
-
 
271
			foreach ($doc as $cle => $valeur) {
-
 
272
				$doc[$cle] = $this->remplacerSautsDeLigne($valeur);
-
 
273
			}
-
 
274
		}
230
		$this->messages[] = array('message' => $message, 'resultat' => true);
275
		return $doc;
231
	}
276
	}
232
	
277
	
Line 233... Line 278...
233
	private function ecrireFichierBdnt(&$contenu) {
278
	private function ecrireFichierBdnt(&$contenu) {
234
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_bdnt'];
279
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_bdnt'];
235
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
280
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
236
		
281
		
237
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
282
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
238
			$this->ajouterMessage("Écriture du fichier bdnt réussie.");
283
			$this->ajouterMessage("Écriture du fichier bdnt réussie.");
239
			$this->signature_md5 = md5_file($fichier_chemin);
284
			$this->signature_md5 = md5_file($fichier_chemin);
Line 240... Line 285...
240
			$this->ajouterMessage("Signature MD5 du fichier bdnt :".$this->signature_md5);
285
			$this->ajouterMessage("Signature MD5 du fichier bdnt :".$this->signature_md5);
241
			$this->ajouterMessage("Nombre de combinaisons traités : ".$this->noms_stat['combinaison']);
286
			$this->ajouterMessage("Nombre de combinaisons traitées : ".$this->noms_stat['combinaison']);
242
		}
287
		}
-
 
288
	}
-
 
289
	
-
 
290
	private function getBaseNomFichier() {
-
 
291
		return strtolower($this->meta['acronyme'].'_v'.$this->meta['version']);
-
 
292
	}
-
 
293
		
-
 
294
	private function creerFichierBdntPartiel(&$donnees) {
-
 
295
		$this->definirChampsPartiel();
-
 
296
		Debug::printr(current($donnees['noms']));
-
 
297
		$donnees['champs_partiel'] = $this->champs_nom_partiel;
-
 
298
		$donnees['dernier_champ'] = end($this->champs_nom_partiel);
-
 
299
		$bdnt_partielle_tsv =& $this->getVue('versionnage/squelettes/bdnt_partiel', &$donnees, '.tpl.tsv');
-
 
300
		$this->ecrireFichierBdntPartielle($bdnt_partielle_tsv);
-
 
301
	}
-
 
302
	
-
 
303
	private function definirChampsPartiel() {
-
 
304
		$this->champs_nom_partiel = explode(',', $this->manuel['champs_partiel']);
-
 
305
		Debug::printr("Champs partiels : ".print_r($this->champs_nom_partiel,true));
-
 
306
	}
-
 
307
	
-
 
308
	private function ecrireFichierBdntPartielle(&$contenu) {
-
 
309
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_bdnt'];
-
 
310
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
-
 
311
		
-
 
312
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
-
 
313
			$this->ajouterMessage("Écriture du fichier de la bdnt partielle réussie.");
Line 243... Line 314...
243
	}
314
			$this->signature_md5_partiel = md5_file($fichier_chemin);
244
	
315
			$this->ajouterMessage("Signature MD5 du fichier bdnt partiel :".$this->signature_md5_partiel);
245
	private function getBaseNomFichier() {
316
			$this->ajouterMessage("Nombre de combinaisons traitées : ".$this->noms_stat['combinaison']);
246
		return strtolower($this->meta['acronyme'].'_v'.$this->meta['version']);
317
		}
247
	}
318
	}
248
	
319
	
249
	private function ecrireFichier($fichier_chemin, &$contenu) {
320
	private function ecrireFichier($fichier_chemin, &$contenu) {
-
 
321
		$retour = true;
250
		$retour = true;
322
		if (file_put_contents($fichier_chemin, $contenu) == false) {
251
		if (file_put_contents($fichier_chemin, $contenu) == false) {
323
			$e = "Une erreur est survenu lors de l'écriture du fichier : $fichier_chemin";
Line 252... Line 324...
252
			$e = "Une erreur est survenu lors de l'écriture du fichier : $fichier_chemin";
324
			$this->ajouterMessage($e);
-
 
325
			$retour = false;
253
			$this->ajouterMessage($e);
326
		}
254
			$retour = false;
327
		$contenu = null;
255
		}
328
		return $retour;
256
		return $retour;
329
	}
257
	}
330
	
Line 268... Line 341...
268
				$e = "La code de la version préalablement versionnée ($code_projet_precedent) est le même que celui ".
341
				$e = "La code de la version préalablement versionnée ($code_projet_precedent) est le même que celui ".
269
					"de la demande actuel ({$this->version_courante}) pour ce projet, aucun fichier différentiel ne sera créé.";
342
					"de la demande actuel ({$this->version_courante}) pour ce projet, aucun fichier différentiel ne sera créé.";
270
				$this->ajouterMessage($e);
343
				$this->ajouterMessage($e);
271
			} else {
344
			} else {
272
				$this->noms_precedents = $this->referentielDao->getTout($code_projet_precedent);
345
				$this->noms_precedents = $this->referentielDao->getTout($code_projet_precedent);
273
				$donnees = array();
-
 
274
				$donnees['diff'] =& $this->realiserDiff();
346
				$donnees['diff'] = $this->realiserDiff();
275
				$donnees['champs'] = $this->champs_nom;
347
				$donnees['champs'] = $this->diff_champs_nom;
276
				$diff_tsv = $this->getVue('versionnage/squelettes/diff', &$donnees, '.tpl.tsv');
348
				$diff_tsv =& $this->getVue('versionnage/squelettes/diff', &$donnees, '.tpl.tsv');
277
				$this->ecrireFichierDiff($diff_tsv);
349
				$this->ecrireFichierDiff($diff_tsv);
278
			}
350
			}
279
		}
351
		}
-
 
352
		return $donnees;
280
	}
353
	}
Line 281... Line 354...
281
	
354
	
282
	private function realiserDiff() {
355
	private function realiserDiff() {
283
		$diff = array();
356
		$this->chargerTableauChampsModifTypes();
-
 
357
		$this->noms_stat['modification'] = 0;
284
		$this->noms_stat['modification'] = 0;
358
		
285
		$i = 0;
359
		$diff = array();
-
 
360
		foreach ($this->noms as $id => $nom) {
286
		foreach ($this->noms as $id => &$nom) {
361
			$this->noms[$id] = null;
287
			$infos = array();
362
			$infos = array();
288
			if (!isset($this->noms_precedents[$id])) {
-
 
289
				$infos = $nom;
363
			if (!isset($this->noms_precedents[$id])) {
290
				$infos['modification_type'] = 'A';
-
 
291
				$infos['modification_type_1'] = '0';
-
 
292
				$infos['modification_type_2'] = '0';
-
 
293
				$infos['modification_type_3'] = '0';
-
 
294
				$this->noms_stat['modification']++;
364
				$infos = $this->traiterDiffAjout($nom);
295
			} else {
365
			} else {
-
 
366
				$nom_precedent = $this->noms_precedents[$id];
296
				$nom_precedent =& $this->noms_precedents[$id];
367
				$this->noms_precedents[$id] = null;
-
 
368
				$infos = $this->traiterDiffModif($nom, $nom_precedent);
-
 
369
			}
-
 
370
			
-
 
371
			if (count($infos) > 0) {
-
 
372
				$infos = $this->remplacerTabulation($infos);
-
 
373
				$infos = $this->remplacerSautsDeLigne($infos);
-
 
374
				$diff[$id] = $infos;
-
 
375
			}
297
				$nom_diff = array_diff_assoc($nom, $nom_precedent);
376
		}
-
 
377
		return $diff;
-
 
378
	}
-
 
379
	
-
 
380
	private function traiterDiffAjout(&$nom) {
298
				Debug::printr($nom_diff);
381
		$infos = $nom;
-
 
382
		$infos['modification_type'] = 'A';
-
 
383
		$infos['modification_type_1'] = '0';
-
 
384
		$infos['modification_type_2'] = '0';
299
				if (count($nom_diff) > 0) {
385
		$infos['modification_type_3'] = '0';
-
 
386
		$this->noms_stat['modification']++;
-
 
387
		return $infos;
-
 
388
	}
-
 
389
	
-
 
390
	private function traiterDiffModif(&$nom, &$nom_precedent) {
-
 
391
		$infos = array();
-
 
392
		$nom_diff = array_diff_assoc($nom, $nom_precedent);		$bdnt_partielle_tsv = 'trest';
300
					$this->noms_stat['modification']++;
393
		if (count($nom_diff) > 0) {
301
					$modif['modification_type'] = 'M';
394
			$modif['modification_type'] = 'M';
302
					$modif['modification_type_1'] = '0';
395
			$modif['modification_type_1'] = '0';
303
					$modif['modification_type_2'] = '0';
396
			$modif['modification_type_2'] = '0';
304
					$modif['modification_type_3'] = '0';
-
 
-
 
397
			$modif['modification_type_3'] = '0';
305
					$this->chargerTableauChampsModifTypes();
398
			
306
					foreach ($this->champs_nom as $champ) {
399
			foreach ($this->champs_nom as $champ) {
307
						if (isset($nom_diff[$champ])) {
400
				if (isset($nom_diff[$champ])) {
308
							$infos[$champ] = $nom_diff[$champ];
401
					$infos[$champ] = $nom_diff[$champ];
309
							$type = $this->getDiffType($champ);
402
					$type = $this->getDiffType($champ);
310
							$modif['modification_type_'.$type] = '1';
403
					$modif['modification_type_'.$type] = '1';
311
						} else {
404
				} else {
312
							$infos[$champ] = '';
405
					if ($champ == 'num_nom') {
313
						}
406
						$infos[$champ] = $nom[$champ];
314
					}
-
 
315
					foreach ($modif as $cle => $val) {
407
					} else {
316
						$infos[$cle] = $val;
408
						$infos[$champ] = '';
317
					}
409
					}
318
				}
410
				}
-
 
411
			}
319
			}
412
			
320
			$infos = $this->remplacerTabulation($infos);
-
 
321
			$infos = $this->remplacerSautsDeLigne($infos);
413
			foreach ($modif as $cle => $val) {
322
			Debug::printr($infos);
-
 
323
			Debug::printr("-------------------------------------------------");
414
				$infos[$cle] = $val;
-
 
415
			}
324
			$diff[$id][] = $infos;
416
			
325
			if ($i == 100) break;
417
			$this->noms_stat['modification']++;
326
		}
418
		}
327
		return $diff;
419
		return $infos;
Line 328... Line 420...
328
	}
420
	}
329
	
421
	
330
	private function chargerTableauChampsModifTypes() {
422
	private function chargerTableauChampsModifTypes() {
Line 338... Line 430...
338
	private function getDiffType($champ_nom) {
430
	private function getDiffType($champ_nom) {
339
		$type = isset($this->diff_modif_types[$champ_nom]) ? $this->diff_modif_types[$champ_nom] : '3';
431
		$type = isset($this->diff_modif_types[$champ_nom]) ? $this->diff_modif_types[$champ_nom] : '3';
340
		return $type;
432
		return $type;
341
	}
433
	}
Line 342... Line 434...
342
	
434
	
343
	private function ecrireFichierDiff($contenu) {
435
	private function ecrireFichierDiff(&$contenu) {
344
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_diff'];
436
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_diff'];
Line 345... Line 437...
345
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
437
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
346
		
438
		
347
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
439
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
348
			$this->ajouterMessage("Écriture du fichier diff réussie.");
440
			$this->ajouterMessage("Écriture du fichier diff réussie.");
Line -... Line 441...
-
 
441
		}
-
 
442
	}
-
 
443
	
-
 
444
	private function creerFichierDiffPartiel(&$donnees) {
-
 
445
		if (count($donnees) > 0) {
-
 
446
			$donnees['champs_partiel_diff'] = array_merge($this->champs_nom_partiel, $this->champs_diff);
-
 
447
			$donnees['dernier_champ'] = end($donnees['champs_partiel_diff']);
-
 
448
			$diff_tsv_partiel =& $this->getVue('versionnage/squelettes/diff_partiel', &$donnees, '.tpl.tsv');
-
 
449
			$this->ecrireFichierDiffPartiel($diff_tsv_partiel);
-
 
450
		}
-
 
451
	}
-
 
452
	
-
 
453
	private function ecrireFichierDiffPartiel(&$contenu) {
-
 
454
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_diff'];
-
 
455
		$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
-
 
456
		
-
 
457
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
-
 
458
			$this->ajouterMessage("Écriture du fichier diff partiel réussie.");
349
		}
459
		}
350
	}
460
	}
351
	
461
	
352
	private function creerFichierMeta() {
462
	private function creerFichierMeta() {
353
		$donnees = array();
463
		$donnees = array();
Line 354... Line 464...
354
		$donnees = $this->meta;
464
		$donnees = $this->meta;
355
		$donnees['stats'] = $this->noms_stat;
465
		$donnees['stats'] = $this->noms_stat;
Line 356... Line 466...
356
		$donnees['signature'] = $this->signature_md5;
466
		$donnees['signature'] = $this->signature_md5;
357
		
467
		
-
 
468
		$donnees = $this->remplacerTabulation($donnees);
358
		$donnees = $this->remplacerTabulation($donnees);
469
		$donnees = $this->remplacerSautsDeLigne($donnees);
Line 359... Line 470...
359
		$donnees = $this->remplacerSautsDeLigne($donnees);
470
		
360
		
471
		$meta_tsv =& $this->getVue('versionnage/squelettes/meta', &$donnees, '.tpl.tsv');
361
		$meta_tsv = $this->getVue('versionnage/squelettes/meta', $donnees, '.tpl.tsv');
472
		$this->ecrireFichierMeta($meta_tsv);
-
 
473
		return $donnees;
362
		$this->ecrireFichierMeta($meta_tsv);
474
	}
363
	}
475
	
364
	
476
	private function ecrireFichierMeta(&$contenu) {
365
	private function remplacerTabulation($doc) {
-
 
366
		if (is_string($doc)) {
477
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_meta'];
367
			$doc = str_replace("\t", ' ', $doc);
-
 
368
		} else if (is_array($doc) && count($doc) > 0) {
478
		$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
Line 369... Line 479...
369
			foreach ($doc as $cle => $valeur) {
479
		
370
				$doc[$cle] = $this->remplacerTabulation($valeur);
-
 
371
			}
-
 
372
		}
480
		if ($this->ecrireFichier($fichier_chemin, $contenu)) {
373
		return $doc;
481
			$this->ajouterMessage("Écriture du fichier meta réussie.");
374
	}
-
 
375
	
482
			$this->archiverMetadonnees();
376
	private function remplacerSautsDeLigne($doc) {
-
 
377
		if (is_string($doc)) {
-
 
378
			$a_remplacer = array("\r", "\n");
-
 
379
			$doc = str_replace($a_remplacer, ' ', $doc);
483
		}
Line 380... Line 484...
380
		} else if (is_array($doc) && count($doc) > 0) {
484
	}
381
			foreach ($doc as $cle => $valeur) {
485
	
382
				$doc[$cle] = $this->remplacerSautsDeLigne($valeur);
486
	private function creerFichierMetaPartiel(&$donnees) {
Line 383... Line 487...
383
			}
487
		$donnees['signature'] = $this->signature_md5_partiel;
384
		}
488
		$meta_tsv_partiel =& $this->getVue('versionnage/squelettes/meta', &$donnees, '.tpl.tsv');
385
		return $doc;
-
 
386
	}
489
		$this->ecrireFichierMetaPartiel($meta_tsv_partiel);
387
	
490
	}
Line 388... Line 491...
388
	private function ecrireFichierMeta($contenu) {
491
	
389
		$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_meta'];
492
	private function ecrireFichierMetaPartiel(&$contenu) {
Line 424... Line 527...
424
		$this->noms_stat = null; 
527
		$this->noms_stat = null; 
425
	}
528
	}
Line 426... Line 529...
426
	
529
	
427
	private function copierManuel() {
530
	private function copierManuel() {
428
		$fichier_source = $this->manuel_chemin.$this->manuel_nom;
531
		$fichier_source = $this->manuel_chemin.$this->manuel_nom;
-
 
532
		$fichiers_destination[] = $this->zip_chemin_dossier.$this->manuel_nom;
-
 
533
		$fichiers_destination[] = $this->zip_chemin_dossier_partiel.$this->manuel_nom;
429
		$fichier_destination = $this->zip_chemin_dossier.$this->manuel_nom;
534
		foreach ($fichiers_destination as $destination) {
430
		if (copy($fichier_source, $fichier_destination) === false) {
535
			if (copy($fichier_source, $destination) === false) {
-
 
536
				$this->ajouterMessage("La copie du manuel vers '$destination' a échouée.");
431
			$this->ajouterMessage("La copie du manuel '$fichier_destination' a échouée.");
537
			}
432
		}
538
		}
Line 433... Line 539...
433
	}
539
	}
434
	
540
	
-
 
541
	private function creerFichiersZip() {
-
 
542
		$this->zipper($this->zip_chemin_fichier, $this->zip_chemin_dossier);
-
 
543
		$this->zipper($this->zip_chemin_fichier_partiel, $this->zip_chemin_dossier_partiel);
-
 
544
	}
-
 
545
	
435
	private function creerFichierZip() {
546
	private function zipper($fichier_zip, $dossier_a_zipper) {
436
		$fichierZip = new PclZip($this->zip_chemin_fichier);
547
		$zip = new PclZip($fichier_zip);
437
		if ($fichierZip->add($this->zip_chemin_dossier, PCLZIP_OPT_REMOVE_ALL_PATH) == 0) {
548
		if ($zip->add($dossier_a_zipper, PCLZIP_OPT_REMOVE_ALL_PATH) == 0) {
438
			$e = "La création du fichier zip '$this->zip_chemin_fichier' a échoué avec l'erreur : ".$fichierZip->errorInfo(true);
549
			$e = "La création du fichier zip '$fichier_zip' a échoué avec l'erreur : ".$zip->errorInfo(true);
439
			$this->ajouterMessage($e);
550
			$this->ajouterMessage($e);
Line 440... Line 551...
440
		}	
551
		}
441
	}
552
	}
442
	
-
 
443
	private function nettoyerFichiers() {
-
 
444
		$dossier = $this->zip_chemin_dossier;
-
 
445
		if (is_dir($dossier)) {
-
 
446
			$objets = scandir($dossier);
553
	
447
			foreach ($objets as $objet) {
-
 
448
				if ($objet != '.' && $objet != '..') {
-
 
449
					if (filetype($dossier.'/'.$objet) == 'dir') {
-
 
450
						rrmdir($dossier.'/'.$objet);
-
 
451
					} else {
-
 
452
						unlink($dossier.'/'.$objet);
-
 
453
					}
-
 
454
				}
-
 
455
			}
-
 
456
			reset($objets);
554
	private function nettoyerFichiers() {
Line 457... Line 555...
457
			rmdir($dossier);
555
		Fichier::supprimerDossier($this->zip_chemin_dossier);
458
		}
556
		Fichier::supprimerDossier($this->zip_chemin_dossier_partiel);
459
	}
557
	}