Subversion Repositories Applications.referentiel

Compare Revisions

Ignore whitespace Rev 50 → Rev 51

/trunk/scripts/modules/versionnage/Versionnage.php
22,11 → 22,20
private $projet = null;
private $traitement = null;
private $meta = null;
private $messages = null;
private $manuel = null;
private $noms = null;
private $noms_precedents = null;
private $noms_stat = null;
private $champs_ordre = null;
private $champs_nom = null;
private $diff_modif_types = null;
private $signature_md5 = null;
private $resultatDao = null;
private $traitementDao = null;
private $metaDao = null;
private $tableStructureDao = null;
private $referentielDao = null;
52,10 → 61,11
$cmd = $this->getParam('a');
switch ($cmd) {
case 'tout' :
$this->metaDao = new MetaDao();
$this->resultatDao = new ResultatDao();
$this->referentielDao = new ReferentielDao();
$this->manuel = parse_ini_file(Config::get('chemin_appli').DS.'..'.DS.'configurations'.DS.'referentiel_v2.1.ini');
Debug::printr('Départ lancement test:');
Debug::printr('Départ lancement versionnage:');
$this->lancerVersionnage();
break;
default :
67,33 → 77,76
}
 
public function lancerVersionnage() {
// Récupération des données à tester
$noms = $this->referentielDao->getTout($this->projet);
Debug::printr('Nbre noms :'.count($noms));
$this->chargerTraitementParametre();
$this->archiver();
$this->chargerNomsATraiter();
$this->analyserNomsATraiter();
$this->creerFichiers();
$this->traiterMessages();
}
$this->versionnerBdnt($noms);
$this->traiterMessagesErreur();
private function chargerTraitementParametre() {
$this->meta = unserialize($this->traitement['script_parametres']);
}
private function versionnerBdnt($noms) {
Debug::printr("Element courrant du tableau des noms : ".print_r(current($noms),true));
//Debug::printr("Taille mémoire du tableau des noms : ".Debug::tailleMemoireVar($noms));
$champs_ordre = $this->determinerOrdreDesChamps(current($noms));
Debug::printr("Tableau ordre des champs : ".print_r($champs_ordre, true));
private function archiver() {
$ok = $this->referentielDao->archiver($this->projet, $this->meta['version']);
if ($ok) {
$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a réussi";
$this->ajouterMessage($m);
} else {
$m = "L'archivage de la version '{$this->meta['version']}' du référentiel '{$this->projet}' a échoué";
$this->ajouterMessage($m);
}
}
private function chargerNomsATraiter() {
$archive_courante = strtolower($this->projet).'_v'.str_replace('.', '_', $this->meta['version']);
Debug::printr("Nom archive courante :".$archive_courante);
$this->noms = $this->referentielDao->getTout($archive_courante);
}
private function analyserNomsATraiter() {
$this->noms_stat['combinaison'] = $this->getNombreCombinaison();
$this->noms_stat['taxon'] = $this->getNombreTaxon();
Debug::printr("Stats :".print_r($this->noms_stat, true));
}
private function getNombreCombinaison() {
return count($this->noms);
}
private function getNombreTaxon() {
$nbre = 0;
foreach ($this->noms as $nom) {
if ($nom['num_nom_retenu'] == $nom['num_nom']) {
$nbre++;
}
}
return $nbre;
}
private function creerFichiers() {
// Respecter l'ordre de traitement : BDNT puis DIFF puis META
$this->creerFichierBdnt();
$this->creerFichierDiff();
$this->creerFichierMeta();
}
private function creerFichierBdnt() {
Debug::printr("Element courrant du tableau des noms : ".print_r(current($this->noms),true));
//Debug::printr("Taille mémoire du tableau des noms : ".Debug::tailleMemoireVar($this->noms));
$this->determinerOrdreDesChamps();
$this->definirNomDesChamps();
$donnees = array();
$donnees['champs'] = array_flip($champs_ordre);
//$donnees['noms'] = $noms;
foreach ($noms as $id => $nom) {
// Suppression de la ligne du tableau pour gagner de l'espace mémoire
unset($noms[$id]);
$donnees['champs'] = $this->champs_nom;
foreach ($this->noms as &$nom) {
$infos = array();
foreach ($nom as $champ => $valeur) {
if (isset($champs_ordre[$champ])) {
$ordre = $champs_ordre[$champ];
$infos[$ordre] = $valeur;
foreach ($nom as $champ => &$valeur) {
if (isset($this->champs_ordre[$champ])) {
$ordre = $this->champs_ordre[$champ];
$infos[$ordre] = trim($valeur);
} else {
$e = "Le champ '$champ' n'a pas été pris en compte dans l'attribution de l'ordre des champs.";
$this->ajouterMessage($e);
102,22 → 155,23
$donnees['noms'][] = $infos;
}
$bdtn_tsv = $this->getVue('versionnage/squelettes/bdnt', $donnees, '.tpl.tsv');
if (file_put_contents(Config::get('chemin_referentiel_zip').'bdnt.txt', $bdtn_tsv) == false) {
Debug::printr("une erreur est survenu lors de l'écriture du fichier");
} else {
}
$bdnt_tsv = $this->getVue('versionnage/squelettes/bdnt', $donnees, '.tpl.tsv');
$this->ecrireFichierBdnt($bdnt_tsv);
}
private function determinerOrdreDesChamps($nom) {
private function determinerOrdreDesChamps() {
$champs_ordre = explode(',', $this->manuel['champs']);
$champs_ordre = array_flip($champs_ordre);
$champs_ordre = $this->attribuerOrdreChampsSupplémentaires($champs_ordre, $nom);
$nom_courant = current($this->noms);
$champs_ordre = $this->attribuerOrdreChampsSupplémentaires($champs_ordre, $nom_courant);
asort($champs_ordre);
return $champs_ordre;
$this->champs_ordre = $champs_ordre;
}
private function definirNomDesChamps() {
$this->champs_nom = array_flip($this->champs_ordre);
}
private function attribuerOrdreChampsSupplémentaires($champs_ordre, $nom) {
foreach ($nom as $champ => $info) {
if (!isset($champs_ordre[$champ])) {
132,6 → 186,151
$this->messages[] = array($titre, $message);
}
private function ecrireFichierBdnt($contenu) {
$fichier_nom = $this->getBaseNomFichier().'_ref.txt';
$fichier_chemin = Config::get('chemin_referentiel_zip').$fichier_nom;
if ($this->ecrireFichier($fichier_chemin, $contenu)) {
$this->ajouterMessage("Écriture du fichier bdnt réussie.");
$this->signature_md5 = md5_file($fichier_chemin);
$this->ajouterMessage("Signature MD5 du fichier bdnt :".$this->signature_md5);
$this->ajouterMessage("Nombre de noms traités : ".count($noms));
}
}
private function getBaseNomFichier() {
return strtolower($this->meta['acronyme'].'_v'.$this->meta['version']);
}
private function ecrireFichier($fichier_chemin, $contenu) {
$retour = true;
if (file_put_contents($fichier_chemin, $contenu) == false) {
$e = "Une erreur est survenu lors de l'écriture du fichier : $fichier_chemin";
$this->ajouterMessage($e);
$retour = false;
}
return $retour;
}
private function creerFichierDiff() {
$derniere_meta = $this->metaDao->getDerniere($this->projet);
if ($derniere_meta === false) {
$this->ajouterMessage("Premier versionnage pour ce projet, aucun fichier différentiel ne sera créé.");
} else {
$code_projet_precedent = strtolower($derniere_meta['code']).'_v'.str_replace('.', '_', $derniere_meta['version']);
$this->noms_precedents = $this->referentielDao->getTout($code_projet_precedent);
$donnees = array();
$donnees['diff'] = $this->realiserDiff();
$donnees['champs'] = $this->champs_nom;
$diff_tsv = $this->getVue('versionnage/squelettes/diff', $donnees, '.tpl.tsv');
$this->ecrireFichierDiff($diff_tsv);
}
}
private function realiserDiff() {
$diff = array();
$this->noms_stat['modification'] = 0;
foreach ($this->noms as $id => &$nom) {
if (!isset($this->noms_precedents[$id])) {
$diff[$id] = $nom;
$diff[$id]['modification_type'] = 'A';
$diff[$id]['modification_type_1'] = '0';
$diff[$id]['modification_type_2'] = '0';
$diff[$id]['modification_type_3'] = '0';
$this->noms_stat['modification']++;
} else {
$nom_precedent =& $this->noms_precedents[$id];
$nom_diff = array_diff_assoc($noms, $nom_precedent);
if (count($nom_diff) > 0) {
$this->noms_stat['modification']++;
$modif['modification_type'] = 'M';
$modif['modification_type_1'] = '0';
$modif['modification_type_2'] = '0';
$modif['modification_type_3'] = '0';
$this->chargerTableauChampsModifTypes();
foreach ($this->champs_nom as $champ) {
if (isset($nom_diff[$champ])) {
$diff[$id][$champ] = $nom_diff[$champ];
$type = $this->getDiffType($champ);
$modif['modification_type_'.$type] = '1';
} else {
$diff[$id][$champ] = '';
}
}
foreach ($modif as $cle => $val) {
$diff[$id][$cle] = $val;
}
}
}
}
return $diff;
}
private function chargerTableauChampsModifTypes() {
$champs = explode(',', $this->manuel['champs_diff_type']);
foreach ($champs as $champ) {
list($champ_nom, $type) = explode('=', $champ);
$this->diff_modif_types[$champ_nom] = $type;
}
}
private function getDiffType($champ_nom) {
$type = isset($this->diff_modif_types[$champ_nom]) ? $this->diff_modif_types[$champ_nom] : '3';
return $type;
}
private function ecrireFichierDiff($contenu) {
$fichier_nom = $this->getBaseNomFichier().'diff.txt';
$fichier_chemin = Config::get('chemin_referentiel_zip').$fichier_nom;
if ($this->ecrireFichier($fichier_chemin, $contenu)) {
$this->ajouterMessage("Écriture du fichier diff réussie.");
}
}
private function creerFichierMeta() {
$donnees = array();
$donnees = $this->meta;
$donnees['stats'] = $this->noms_stat;
$donnees['signature'] = $this->signature_md5;
$meta_tsv = $this->getVue('versionnage/squelettes/meta', $donnees, '.tpl.tsv');
$this->ecrireFichierMeta($meta_tsv);
}
private function ecrireFichierMeta($contenu) {
$fichier_nom = $this->getBaseNomFichier().'_meta.txt';
$fichier_chemin = Config::get('chemin_referentiel_zip').$fichier_nom;
if ($this->ecrireFichier($fichier_chemin, $contenu)) {
$this->ajouterMessage("Écriture du fichier meta réussie.");
$this->archiverMetadonnees();
}
}
private function archiverMetadonnees() {
$metadonnees = $this->meta;
$metadonnees['code'] = $this->meta['acronyme'];
unset($metadonnees['acronyme']);
$metadonnees['domaine_taxo'] = $this->meta['dom_tax'];
unset($metadonnees['dom_tax']);
$metadonnees['domaine_geo'] = $this->meta['dom_geo'];
unset($metadonnees['dom_geo']);
$metadonnees['domaine_nom'] = $this->meta['dom_code'];
unset($metadonnees['dom_code']);
$metadonnees['auteur'] = $this->meta['auteur_principal'];
unset($metadonnees['auteur_principal']);
$metadonnees['date_production'] = $this->meta['date_prod'];
unset($metadonnees['date_prod']);
$metadonnees['droit'] = $this->meta['copyright'];
unset($metadonnees['copyright']);
$ok = $this->metaDao->ajouter($metadonnees);
if ($ok === false) {
$this->ajouterMessage("L'archivage des métadonnées a échoué.");
}
}
private function traiterMessages() {
if (isset($this->messages)) {
foreach ($this->messages as $message) {