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