| Line 20... |
Line 20... |
| 20 |
|
20 |
|
| Line 21... |
Line 21... |
| 21 |
const SCRIPT_NOM = 'versionnage';
|
21 |
const SCRIPT_NOM = 'versionnage';
|
| 22 |
|
22 |
|
| - |
|
23 |
private $projet = null;
|
| 23 |
private $projet = null;
|
24 |
private $traitement = null;
|
| 24 |
private $traitement = null;
|
25 |
private $meta = null;
|
| - |
|
26 |
private $messages = null;
|
| - |
|
27 |
private $manuel = null;
|
| - |
|
28 |
private $noms = null;
|
| - |
|
29 |
private $noms_precedents = null;
|
| - |
|
30 |
private $noms_stat = null;
|
| - |
|
31 |
private $champs_ordre = null;
|
| - |
|
32 |
private $champs_nom = null;
|
| Line 25... |
Line 33... |
| 25 |
private $messages = null;
|
33 |
private $diff_modif_types = null;
|
| 26 |
private $manuel = null;
|
34 |
private $signature_md5 = null;
|
| - |
|
35 |
|
| 27 |
|
36 |
private $resultatDao = null;
|
| 28 |
private $resultatDao = null;
|
37 |
private $traitementDao = null;
|
| Line 29... |
Line 38... |
| 29 |
private $traitementDao = null;
|
38 |
private $metaDao = null;
|
| 30 |
private $tableStructureDao = null;
|
39 |
private $tableStructureDao = null;
|
| Line 50... |
Line 59... |
| 50 |
|
59 |
|
| 51 |
// Lancement du test demandé
|
60 |
// Lancement du test demandé
|
| 52 |
$cmd = $this->getParam('a');
|
61 |
$cmd = $this->getParam('a');
|
| 53 |
switch ($cmd) {
|
62 |
switch ($cmd) {
|
| - |
|
63 |
case 'tout' :
|
| 54 |
case 'tout' :
|
64 |
$this->metaDao = new MetaDao();
|
| 55 |
$this->resultatDao = new ResultatDao();
|
65 |
$this->resultatDao = new ResultatDao();
|
| 56 |
$this->referentielDao = new ReferentielDao();
|
66 |
$this->referentielDao = new ReferentielDao();
|
| 57 |
$this->manuel = parse_ini_file(Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS.'referentiel_v2.1.ini');
|
67 |
$this->manuel = parse_ini_file(Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS.'referentiel_v2.1.ini');
|
| 58 |
Debug::printr('Départ lancement test:');
|
68 |
Debug::printr('Départ lancement versionnage:');
|
| 59 |
$this->lancerVersionnage();
|
69 |
$this->lancerVersionnage();
|
| 60 |
break;
|
70 |
break;
|
| 61 |
default :
|
71 |
default :
|
| 62 |
$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
|
72 |
$this->traiterErreur('Erreur : la commande "%s" n\'existe pas!', array($cmd));
|
| Line 65... |
Line 75... |
| 65 |
Debug::printr('Termine:'.$this->traitementDao->terminerTraitement($this->traitement['id_traitement']));
|
75 |
Debug::printr('Termine:'.$this->traitementDao->terminerTraitement($this->traitement['id_traitement']));
|
| 66 |
}
|
76 |
}
|
| 67 |
}
|
77 |
}
|
| Line 68... |
Line 78... |
| 68 |
|
78 |
|
| 69 |
public function lancerVersionnage() {
|
79 |
public function lancerVersionnage() {
|
| - |
|
80 |
$this->chargerTraitementParametre();
|
| 70 |
// Récupération des données à tester
|
81 |
$this->archiver();
|
| 71 |
$noms = $this->referentielDao->getTout($this->projet);
|
82 |
$this->chargerNomsATraiter();
|
| - |
|
83 |
$this->analyserNomsATraiter();
|
| - |
|
84 |
$this->creerFichiers();
|
| - |
|
85 |
$this->traiterMessages();
|
| Line -... |
Line 86... |
| - |
|
86 |
}
|
| - |
|
87 |
|
| - |
|
88 |
private function chargerTraitementParametre() {
|
| - |
|
89 |
$this->meta = unserialize($this->traitement['script_parametres']);
|
| - |
|
90 |
}
|
| - |
|
91 |
|
| - |
|
92 |
private function archiver() {
|
| - |
|
93 |
$ok = $this->referentielDao->archiver($this->projet, $this->meta['version']);
|
| 72 |
Debug::printr('Nbre noms :'.count($noms));
|
94 |
if ($ok) {
|
| - |
|
95 |
$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a réussi";
|
| - |
|
96 |
$this->ajouterMessage($m);
|
| - |
|
97 |
} else {
|
| - |
|
98 |
$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a échoué";
|
| - |
|
99 |
$this->ajouterMessage($m);
|
| - |
|
100 |
}
|
| - |
|
101 |
}
|
| - |
|
102 |
|
| - |
|
103 |
private function chargerNomsATraiter() {
|
| - |
|
104 |
$archive_courante = strtolower($this->projet).'_v'.str_replace('.', '_', $this->meta['version']);
|
| - |
|
105 |
Debug::printr("Nom archive courante :".$archive_courante);
|
| 73 |
|
106 |
$this->noms = $this->referentielDao->getTout($archive_courante);
|
| - |
|
107 |
}
|
| - |
|
108 |
|
| 74 |
$this->versionnerBdnt($noms);
|
109 |
private function analyserNomsATraiter() {
|
| - |
|
110 |
$this->noms_stat['combinaison'] = $this->getNombreCombinaison();
|
| - |
|
111 |
$this->noms_stat['taxon'] = $this->getNombreTaxon();
|
| - |
|
112 |
Debug::printr("Stats :".print_r($this->noms_stat, true));
|
| - |
|
113 |
}
|
| - |
|
114 |
|
| - |
|
115 |
private function getNombreCombinaison() {
|
| - |
|
116 |
return count($this->noms);
|
| - |
|
117 |
}
|
| - |
|
118 |
|
| - |
|
119 |
private function getNombreTaxon() {
|
| - |
|
120 |
$nbre = 0;
|
| - |
|
121 |
foreach ($this->noms as $nom) {
|
| - |
|
122 |
if ($nom['num_nom_retenu'] == $nom['num_nom']) {
|
| - |
|
123 |
$nbre++;
|
| - |
|
124 |
}
|
| 75 |
|
125 |
}
|
| Line -... |
Line 126... |
| - |
|
126 |
return $nbre;
|
| - |
|
127 |
}
|
| - |
|
128 |
|
| - |
|
129 |
private function creerFichiers() {
|
| - |
|
130 |
// Respecter l'ordre de traitement : BDNT puis DIFF puis META
|
| - |
|
131 |
$this->creerFichierBdnt();
|
| - |
|
132 |
$this->creerFichierDiff();
|
| 76 |
$this->traiterMessagesErreur();
|
133 |
$this->creerFichierMeta();
|
| 77 |
}
|
134 |
}
|
| 78 |
|
135 |
|
| 79 |
private function versionnerBdnt($noms) {
|
136 |
private function creerFichierBdnt() {
|
| 80 |
Debug::printr("Element courrant du tableau des noms : ".print_r(current($noms),true));
|
137 |
Debug::printr("Element courrant du tableau des noms : ".print_r(current($this->noms),true));
|
| Line 81... |
Line 138... |
| 81 |
//Debug::printr("Taille mémoire du tableau des noms : ".Debug::tailleMemoireVar($noms));
|
138 |
//Debug::printr("Taille mémoire du tableau des noms : ".Debug::tailleMemoireVar($this->noms));
|
| 82 |
$champs_ordre = $this->determinerOrdreDesChamps(current($noms));
|
139 |
$this->determinerOrdreDesChamps();
|
| 83 |
Debug::printr("Tableau ordre des champs : ".print_r($champs_ordre, true));
|
- |
|
| 84 |
|
- |
|
| 85 |
$donnees = array();
|
140 |
$this->definirNomDesChamps();
|
| 86 |
$donnees['champs'] = array_flip($champs_ordre);
|
- |
|
| 87 |
//$donnees['noms'] = $noms;
|
- |
|
| 88 |
|
141 |
|
| 89 |
foreach ($noms as $id => $nom) {
|
142 |
$donnees = array();
|
| 90 |
// Suppression de la ligne du tableau pour gagner de l'espace mémoire
|
143 |
$donnees['champs'] = $this->champs_nom;
|
| 91 |
unset($noms[$id]);
|
144 |
foreach ($this->noms as &$nom) {
|
| 92 |
$infos = array();
|
145 |
$infos = array();
|
| 93 |
foreach ($nom as $champ => $valeur) {
|
146 |
foreach ($nom as $champ => &$valeur) {
|
| 94 |
if (isset($champs_ordre[$champ])) {
|
147 |
if (isset($this->champs_ordre[$champ])) {
|
| 95 |
$ordre = $champs_ordre[$champ];
|
148 |
$ordre = $this->champs_ordre[$champ];
|
| 96 |
$infos[$ordre] = $valeur;
|
149 |
$infos[$ordre] = trim($valeur);
|
| 97 |
} else {
|
150 |
} else {
|
| 98 |
$e = "Le champ '$champ' n'a pas été pris en compte dans l'attribution de l'ordre des champs.";
|
151 |
$e = "Le champ '$champ' n'a pas été pris en compte dans l'attribution de l'ordre des champs.";
|
| 99 |
$this->ajouterMessage($e);
|
152 |
$this->ajouterMessage($e);
|
| Line 100... |
Line 153... |
| 100 |
}
|
153 |
}
|
| 101 |
}
|
- |
|
| 102 |
$donnees['noms'][] = $infos;
|
154 |
}
|
| 103 |
}
|
- |
|
| 104 |
|
- |
|
| 105 |
$bdtn_tsv = $this->getVue('versionnage/squelettes/bdnt', $donnees, '.tpl.tsv');
|
- |
|
| 106 |
if (file_put_contents(Config::get('chemin_referentiel_zip').'bdnt.txt', $bdtn_tsv) == false) {
|
155 |
$donnees['noms'][] = $infos;
|
| Line 107... |
Line 156... |
| 107 |
Debug::printr("une erreur est survenu lors de l'écriture du fichier");
|
156 |
}
|
| 108 |
} else {
|
157 |
|
| 109 |
|
158 |
$bdnt_tsv = $this->getVue('versionnage/squelettes/bdnt', $donnees, '.tpl.tsv');
|
| - |
|
159 |
$this->ecrireFichierBdnt($bdnt_tsv);
|
| 110 |
}
|
160 |
}
|
| 111 |
}
|
161 |
|
| 112 |
|
162 |
private function determinerOrdreDesChamps() {
|
| - |
|
163 |
$champs_ordre = explode(',', $this->manuel['champs']);
|
| - |
|
164 |
$champs_ordre = array_flip($champs_ordre);
|
| - |
|
165 |
$nom_courant = current($this->noms);
|
| - |
|
166 |
$champs_ordre = $this->attribuerOrdreChampsSupplémentaires($champs_ordre, $nom_courant);
|
| 113 |
private function determinerOrdreDesChamps($nom) {
|
167 |
asort($champs_ordre);
|
| Line 114... |
Line 168... |
| 114 |
$champs_ordre = explode(',', $this->manuel['champs']);
|
168 |
$this->champs_ordre = $champs_ordre;
|
| 115 |
$champs_ordre = array_flip($champs_ordre);
|
169 |
}
|
| 116 |
$champs_ordre = $this->attribuerOrdreChampsSupplémentaires($champs_ordre, $nom);
|
170 |
|
| Line 130... |
Line 184... |
| 130 |
private function ajouterMessage($message) {
|
184 |
private function ajouterMessage($message) {
|
| 131 |
$titre = self::SCRIPT_NOM.' #'.$this->traitement['id_traitement'];
|
185 |
$titre = self::SCRIPT_NOM.' #'.$this->traitement['id_traitement'];
|
| 132 |
$this->messages[] = array($titre, $message);
|
186 |
$this->messages[] = array($titre, $message);
|
| 133 |
}
|
187 |
}
|
| Line -... |
Line 188... |
| - |
|
188 |
|
| - |
|
189 |
private function ecrireFichierBdnt($contenu) {
|
| - |
|
190 |
$fichier_nom = $this->getBaseNomFichier().'_ref.txt';
|
| - |
|
191 |
$fichier_chemin = Config::get('chemin_referentiel_zip').$fichier_nom;
|
| - |
|
192 |
|
| - |
|
193 |
if ($this->ecrireFichier($fichier_chemin, $contenu)) {
|
| - |
|
194 |
$this->ajouterMessage("Écriture du fichier bdnt réussie.");
|
| - |
|
195 |
$this->signature_md5 = md5_file($fichier_chemin);
|
| - |
|
196 |
$this->ajouterMessage("Signature MD5 du fichier bdnt :".$this->signature_md5);
|
| - |
|
197 |
$this->ajouterMessage("Nombre de noms traités : ".count($noms));
|
| - |
|
198 |
|
| - |
|
199 |
}
|
| - |
|
200 |
}
|
| - |
|
201 |
|
| - |
|
202 |
private function getBaseNomFichier() {
|
| - |
|
203 |
return strtolower($this->meta['acronyme'].'_v'.$this->meta['version']);
|
| - |
|
204 |
}
|
| - |
|
205 |
|
| - |
|
206 |
private function ecrireFichier($fichier_chemin, $contenu) {
|
| - |
|
207 |
$retour = true;
|
| - |
|
208 |
if (file_put_contents($fichier_chemin, $contenu) == false) {
|
| - |
|
209 |
$e = "Une erreur est survenu lors de l'écriture du fichier : $fichier_chemin";
|
| - |
|
210 |
$this->ajouterMessage($e);
|
| - |
|
211 |
$retour = false;
|
| - |
|
212 |
}
|
| - |
|
213 |
return $retour;
|
| - |
|
214 |
}
|
| - |
|
215 |
|
| - |
|
216 |
private function creerFichierDiff() {
|
| - |
|
217 |
$derniere_meta = $this->metaDao->getDerniere($this->projet);
|
| - |
|
218 |
if ($derniere_meta === false) {
|
| - |
|
219 |
$this->ajouterMessage("Premier versionnage pour ce projet, aucun fichier différentiel ne sera créé.");
|
| - |
|
220 |
} else {
|
| - |
|
221 |
$code_projet_precedent = strtolower($derniere_meta['code']).'_v'.str_replace('.', '_', $derniere_meta['version']);
|
| - |
|
222 |
$this->noms_precedents = $this->referentielDao->getTout($code_projet_precedent);
|
| - |
|
223 |
$donnees = array();
|
| - |
|
224 |
$donnees['diff'] = $this->realiserDiff();
|
| - |
|
225 |
$donnees['champs'] = $this->champs_nom;
|
| - |
|
226 |
$diff_tsv = $this->getVue('versionnage/squelettes/diff', $donnees, '.tpl.tsv');
|
| - |
|
227 |
$this->ecrireFichierDiff($diff_tsv);
|
| - |
|
228 |
}
|
| - |
|
229 |
}
|
| - |
|
230 |
|
| - |
|
231 |
private function realiserDiff() {
|
| - |
|
232 |
$diff = array();
|
| - |
|
233 |
$this->noms_stat['modification'] = 0;
|
| - |
|
234 |
foreach ($this->noms as $id => &$nom) {
|
| - |
|
235 |
if (!isset($this->noms_precedents[$id])) {
|
| - |
|
236 |
$diff[$id] = $nom;
|
| - |
|
237 |
$diff[$id]['modification_type'] = 'A';
|
| - |
|
238 |
$diff[$id]['modification_type_1'] = '0';
|
| - |
|
239 |
$diff[$id]['modification_type_2'] = '0';
|
| - |
|
240 |
$diff[$id]['modification_type_3'] = '0';
|
| - |
|
241 |
$this->noms_stat['modification']++;
|
| - |
|
242 |
} else {
|
| - |
|
243 |
$nom_precedent =& $this->noms_precedents[$id];
|
| - |
|
244 |
$nom_diff = array_diff_assoc($noms, $nom_precedent);
|
| - |
|
245 |
if (count($nom_diff) > 0) {
|
| - |
|
246 |
$this->noms_stat['modification']++;
|
| - |
|
247 |
$modif['modification_type'] = 'M';
|
| - |
|
248 |
$modif['modification_type_1'] = '0';
|
| - |
|
249 |
$modif['modification_type_2'] = '0';
|
| - |
|
250 |
$modif['modification_type_3'] = '0';
|
| - |
|
251 |
$this->chargerTableauChampsModifTypes();
|
| - |
|
252 |
foreach ($this->champs_nom as $champ) {
|
| - |
|
253 |
if (isset($nom_diff[$champ])) {
|
| - |
|
254 |
$diff[$id][$champ] = $nom_diff[$champ];
|
| - |
|
255 |
$type = $this->getDiffType($champ);
|
| - |
|
256 |
$modif['modification_type_'.$type] = '1';
|
| - |
|
257 |
} else {
|
| - |
|
258 |
$diff[$id][$champ] = '';
|
| - |
|
259 |
}
|
| - |
|
260 |
}
|
| - |
|
261 |
foreach ($modif as $cle => $val) {
|
| - |
|
262 |
$diff[$id][$cle] = $val;
|
| - |
|
263 |
}
|
| - |
|
264 |
}
|
| - |
|
265 |
}
|
| - |
|
266 |
}
|
| - |
|
267 |
return $diff;
|
| - |
|
268 |
}
|
| - |
|
269 |
|
| - |
|
270 |
private function chargerTableauChampsModifTypes() {
|
| - |
|
271 |
$champs = explode(',', $this->manuel['champs_diff_type']);
|
| - |
|
272 |
foreach ($champs as $champ) {
|
| - |
|
273 |
list($champ_nom, $type) = explode('=', $champ);
|
| - |
|
274 |
$this->diff_modif_types[$champ_nom] = $type;
|
| - |
|
275 |
}
|
| - |
|
276 |
}
|
| - |
|
277 |
|
| - |
|
278 |
private function getDiffType($champ_nom) {
|
| - |
|
279 |
$type = isset($this->diff_modif_types[$champ_nom]) ? $this->diff_modif_types[$champ_nom] : '3';
|
| - |
|
280 |
return $type;
|
| - |
|
281 |
}
|
| - |
|
282 |
|
| - |
|
283 |
private function ecrireFichierDiff($contenu) {
|
| - |
|
284 |
$fichier_nom = $this->getBaseNomFichier().'diff.txt';
|
| - |
|
285 |
$fichier_chemin = Config::get('chemin_referentiel_zip').$fichier_nom;
|
| - |
|
286 |
|
| - |
|
287 |
if ($this->ecrireFichier($fichier_chemin, $contenu)) {
|
| - |
|
288 |
$this->ajouterMessage("Écriture du fichier diff réussie.");
|
| - |
|
289 |
}
|
| - |
|
290 |
}
|
| - |
|
291 |
|
| - |
|
292 |
private function creerFichierMeta() {
|
| - |
|
293 |
$donnees = array();
|
| - |
|
294 |
$donnees = $this->meta;
|
| - |
|
295 |
$donnees['stats'] = $this->noms_stat;
|
| - |
|
296 |
$donnees['signature'] = $this->signature_md5;
|
| - |
|
297 |
$meta_tsv = $this->getVue('versionnage/squelettes/meta', $donnees, '.tpl.tsv');
|
| - |
|
298 |
$this->ecrireFichierMeta($meta_tsv);
|
| - |
|
299 |
}
|
| - |
|
300 |
|
| - |
|
301 |
private function ecrireFichierMeta($contenu) {
|
| - |
|
302 |
$fichier_nom = $this->getBaseNomFichier().'_meta.txt';
|
| - |
|
303 |
$fichier_chemin = Config::get('chemin_referentiel_zip').$fichier_nom;
|
| - |
|
304 |
|
| - |
|
305 |
if ($this->ecrireFichier($fichier_chemin, $contenu)) {
|
| - |
|
306 |
$this->ajouterMessage("Écriture du fichier meta réussie.");
|
| - |
|
307 |
$this->archiverMetadonnees();
|
| - |
|
308 |
}
|
| - |
|
309 |
}
|
| - |
|
310 |
|
| - |
|
311 |
private function archiverMetadonnees() {
|
| - |
|
312 |
$metadonnees = $this->meta;
|
| - |
|
313 |
$metadonnees['code'] = $this->meta['acronyme'];
|
| - |
|
314 |
unset($metadonnees['acronyme']);
|
| - |
|
315 |
$metadonnees['domaine_taxo'] = $this->meta['dom_tax'];
|
| - |
|
316 |
unset($metadonnees['dom_tax']);
|
| - |
|
317 |
$metadonnees['domaine_geo'] = $this->meta['dom_geo'];
|
| - |
|
318 |
unset($metadonnees['dom_geo']);
|
| - |
|
319 |
$metadonnees['domaine_nom'] = $this->meta['dom_code'];
|
| - |
|
320 |
unset($metadonnees['dom_code']);
|
| - |
|
321 |
$metadonnees['auteur'] = $this->meta['auteur_principal'];
|
| - |
|
322 |
unset($metadonnees['auteur_principal']);
|
| - |
|
323 |
$metadonnees['date_production'] = $this->meta['date_prod'];
|
| - |
|
324 |
unset($metadonnees['date_prod']);
|
| - |
|
325 |
$metadonnees['droit'] = $this->meta['copyright'];
|
| - |
|
326 |
unset($metadonnees['copyright']);
|
| - |
|
327 |
|
| - |
|
328 |
$ok = $this->metaDao->ajouter($metadonnees);
|
| - |
|
329 |
if ($ok === false) {
|
| - |
|
330 |
$this->ajouterMessage("L'archivage des métadonnées a échoué.");
|
| - |
|
331 |
}
|
| - |
|
332 |
}
|
| 134 |
|
333 |
|
| 135 |
private function traiterMessages() {
|
334 |
private function traiterMessages() {
|
| 136 |
if (isset($this->messages)) {
|
335 |
if (isset($this->messages)) {
|
| 137 |
foreach ($this->messages as $message) {
|
336 |
foreach ($this->messages as $message) {
|
| 138 |
$this->resultatDao->ajouter($this->traitement['id_traitement'], $message);
|
337 |
$this->resultatDao->ajouter($this->traitement['id_traitement'], $message);
|