Subversion Repositories Applications.referentiel

Rev

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

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