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