Subversion Repositories Applications.referentiel

Rev

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

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