Subversion Repositories Applications.referentiel

Compare Revisions

Ignore whitespace Rev 64 → Rev 65

/trunk/scripts/modules/versionnage/squelettes/bdnt_partiel.tpl.tsv
New file
0,0 → 1,3
<?=implode("\t", $champs_partiel)?>
 
<?php foreach ($noms as $nom_infos) : ?><?php foreach ($champs_partiel as $champ) : ?><?=$nom_infos[$champ]?><?=(($dernier_champ == $champ) ? "\n" : "\t")?><?php endforeach; ?><?php endforeach; ?>
/trunk/scripts/modules/versionnage/squelettes/diff_partiel.tpl.tsv
New file
0,0 → 1,3
<?=implode("\t", $champs_partiel_diff)?>
 
<?php foreach ($diff as $id => $nom_infos) : ?><?php foreach ($champs_partiel_diff as $champ) : ?><?=$nom_infos[$champ]?><?=(($dernier_champ == $champ) ? "\n" : "\t")?><?php endforeach; ?><?php endforeach; ?>
/trunk/scripts/modules/versionnage/Versionnage.php
31,6 → 31,8
private $manuel_chemin = null;
private $zip_chemin_dossier = null;
private $zip_chemin_fichier = null;
private $zip_chemin_dossier_partiel = null;
private $zip_chemin_fichier_partiel = null;
private $noms = null;
private $noms_precedents = null;
37,8 → 39,12
private $noms_stat = null;
private $champs_ordre = null;
private $champs_nom = null;
private $champs_nom_partiel = null;
private $champs_diff = null;
private $diff_champs_nom = null;
private $diff_modif_types = null;
private $signature_md5 = null;
private $signature_md5_partiel = null;
private $resultatDao = null;
private $traitementDao = null;
96,7 → 102,7
$this->chargerTraitementParametre();
$this->initialiserNomVersionCOurante();
$this->initialiserCheminsZip();
$this->creerDossierZip();
$this->creerDossiersZip();
$this->archiver();
$this->chargerNomsATraiter();
$this->analyserNomsATraiter();
128,13 → 134,18
private function initialiserCheminsZip() {
$this->zip_chemin_dossier = Config::get('chemin_referentiel_zip').$this->version_courante.DIRECTORY_SEPARATOR;
$this->zip_chemin_fichier = Config::get('chemin_referentiel_zip').$this->version_courante.'.zip';
$this->zip_chemin_dossier_partiel = Config::get('chemin_referentiel_zip').$this->version_courante.'_partiel'.DIRECTORY_SEPARATOR;
$this->zip_chemin_fichier_partiel = Config::get('chemin_referentiel_zip').$this->version_courante.'_partiel.zip';
}
private function creerDossierZip() {
private function creerDossiersZip() {
$recursivite = true;
if (mkdir($this->zip_chemin_dossier, 0777, $recursivite) === false) {
$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier' devant contenir les fichiers a échouée.");
}
if (mkdir($this->zip_chemin_dossier_partiel, 0777, $recursivite) === false) {
$this->ajouterMessage("La création du dossier '$this->zip_chemin_dossier_partiel' devant contenir les fichiers partiels a échouée.");
}
}
private function chargerNomsATraiter() {
163,32 → 174,37
private function creerFichiers() {
// Respecter l'ordre de traitement : BDNT puis DIFF puis META
$this->creerFichierBdnt();
$this->creerFichierDiff();
$this->creerFichierMeta();
$donnees =& $this->creerFichierBdnt();
$this->creerFichierBdntPartiel($donnees);
$donnees = null;
$donnees =& $this->creerFichierDiff();
$this->creerFichierDiffPartiel($donnees);
$donnees = null;
$donnees =& $this->creerFichierMeta();
$this->creerFichierMetaPartiel($donnees);
$donnees = null;
$this->nettoyerMemoire();
$this->copierManuel();
$this->creerFichierZip();
$this->creerFichiersZip();
}
private function creerFichierBdnt() {
$noms =& $this->noms;
reset($this->noms);
Debug::printr("Element courrant du tableau des noms : ".count($this->noms).'-'.print_r(current($this->noms),true));
$this->determinerOrdreDesChamps();
$this->definirNomDesChamps();
$this->definirNomDesChampsDiff();
$donnees = array();
$donnees['champs'] = $this->champs_nom;
foreach ($this->noms as &$nom) {
foreach ($this->noms as $id => &$nom) {
$infos = array();
foreach ($nom as $champ => &$valeur) {
if (isset($this->champs_ordre[$champ])) {
$ordre = $this->champs_ordre[$champ];
$infos[(int) $ordre] = trim($valeur);
foreach ($this->champs_ordre as $champ => $ordre) {
if (isset($nom[$champ])) {
$infos[$champ] = trim($nom[$champ]);
} else {
$e = "Le champ '$champ' n'a pas été pris en compte dans l'attribution de l'ordre des champs.";
$e = "Le champ '$champ' n'a pas été trouvé dans les données du nom : $id.";
$this->ajouterMessage($e);
}
}
195,11 → 211,12
ksort($infos);
$infos = $this->remplacerTabulation($infos);
$infos = $this->remplacerSautsDeLigne($infos);
$donnees['noms'][] = $infos;
$donnees['noms'][$id] = $infos;
}
Debug::printr("Dernier element du tableau des noms [trié] : ".print_r($infos,true));
$bdnt_tsv =& $this->getVue('versionnage/squelettes/bdnt', $donnees, '.tpl.tsv');
$bdnt_tsv =& $this->getVue('versionnage/squelettes/bdnt', &$donnees, '.tpl.tsv');
$this->ecrireFichierBdnt($bdnt_tsv);
return $donnees;
}
private function determinerOrdreDesChamps() {
212,10 → 229,6
Debug::printr("Ordre des champs : ".print_r($this->champs_ordre,true));
}
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])) {
225,11 → 238,43
return $champs_ordre;
}
private function definirNomDesChamps() {
$this->champs_nom = array_flip($this->champs_ordre);
}
private function definirNomDesChampsDiff() {
$this->champs_diff = explode(',', $this->manuel['champs_diff']);
$this->diff_champs_nom = array_merge($this->champs_nom, $this->champs_diff);
}
private function ajouterMessage($message) {
$titre = self::SCRIPT_NOM.' #'.$this->traitement['id_traitement'];
$this->messages[] = array('message' => $message, 'resultat' => true);
}
private function remplacerTabulation($doc) {
if (is_string($doc)) {
$doc = str_replace("\t", ' ', $doc);
} else if (is_array($doc) && count($doc) > 0) {
foreach ($doc as $cle => $valeur) {
$doc[$cle] = $this->remplacerTabulation($valeur);
}
}
return $doc;
}
private function remplacerSautsDeLigne($doc) {
if (is_string($doc)) {
$a_remplacer = array("\r", "\n");
$doc = str_replace($a_remplacer, ' ', $doc);
} else if (is_array($doc) && count($doc) > 0) {
foreach ($doc as $cle => $valeur) {
$doc[$cle] = $this->remplacerSautsDeLigne($valeur);
}
}
return $doc;
}
private function ecrireFichierBdnt(&$contenu) {
$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_bdnt'];
$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
238,7 → 283,7
$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 combinaisons traités : ".$this->noms_stat['combinaison']);
$this->ajouterMessage("Nombre de combinaisons traitées : ".$this->noms_stat['combinaison']);
}
}
245,7 → 290,33
private function getBaseNomFichier() {
return strtolower($this->meta['acronyme'].'_v'.$this->meta['version']);
}
private function creerFichierBdntPartiel(&$donnees) {
$this->definirChampsPartiel();
Debug::printr(current($donnees['noms']));
$donnees['champs_partiel'] = $this->champs_nom_partiel;
$donnees['dernier_champ'] = end($this->champs_nom_partiel);
$bdnt_partielle_tsv =& $this->getVue('versionnage/squelettes/bdnt_partiel', &$donnees, '.tpl.tsv');
$this->ecrireFichierBdntPartielle($bdnt_partielle_tsv);
}
private function definirChampsPartiel() {
$this->champs_nom_partiel = explode(',', $this->manuel['champs_partiel']);
Debug::printr("Champs partiels : ".print_r($this->champs_nom_partiel,true));
}
private function ecrireFichierBdntPartielle(&$contenu) {
$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_bdnt'];
$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
if ($this->ecrireFichier($fichier_chemin, $contenu)) {
$this->ajouterMessage("Écriture du fichier de la bdnt partielle réussie.");
$this->signature_md5_partiel = md5_file($fichier_chemin);
$this->ajouterMessage("Signature MD5 du fichier bdnt partiel :".$this->signature_md5_partiel);
$this->ajouterMessage("Nombre de combinaisons traitées : ".$this->noms_stat['combinaison']);
}
}
private function ecrireFichier($fichier_chemin, &$contenu) {
$retour = true;
if (file_put_contents($fichier_chemin, $contenu) == false) {
253,10 → 324,12
$this->ajouterMessage($e);
$retour = false;
}
$contenu = null;
return $retour;
}
private function creerFichierDiff() {
$donnees = array();
$derniere_meta = $this->metaDao->getDerniere($this->projet);
if (is_null($derniere_meta === false)) {
$this->ajouterMessage("Un problème est survenu lors de la récupération des métadonnées précédentes.");
270,61 → 343,80
$this->ajouterMessage($e);
} else {
$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');
$donnees['diff'] = $this->realiserDiff();
$donnees['champs'] = $this->diff_champs_nom;
$diff_tsv =& $this->getVue('versionnage/squelettes/diff', &$donnees, '.tpl.tsv');
$this->ecrireFichierDiff($diff_tsv);
}
}
return $donnees;
}
private function realiserDiff() {
$this->chargerTableauChampsModifTypes();
$this->noms_stat['modification'] = 0;
$diff = array();
$this->noms_stat['modification'] = 0;
$i = 0;
foreach ($this->noms as $id => &$nom) {
foreach ($this->noms as $id => $nom) {
$this->noms[$id] = null;
$infos = array();
if (!isset($this->noms_precedents[$id])) {
$infos = $nom;
$infos['modification_type'] = 'A';
$infos['modification_type_1'] = '0';
$infos['modification_type_2'] = '0';
$infos['modification_type_3'] = '0';
$this->noms_stat['modification']++;
$infos = $this->traiterDiffAjout($nom);
} else {
$nom_precedent =& $this->noms_precedents[$id];
$nom_diff = array_diff_assoc($nom, $nom_precedent);
Debug::printr($nom_diff);
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])) {
$infos[$champ] = $nom_diff[$champ];
$type = $this->getDiffType($champ);
$modif['modification_type_'.$type] = '1';
} else {
$infos[$champ] = '';
}
$nom_precedent = $this->noms_precedents[$id];
$this->noms_precedents[$id] = null;
$infos = $this->traiterDiffModif($nom, $nom_precedent);
}
if (count($infos) > 0) {
$infos = $this->remplacerTabulation($infos);
$infos = $this->remplacerSautsDeLigne($infos);
$diff[$id] = $infos;
}
}
return $diff;
}
private function traiterDiffAjout(&$nom) {
$infos = $nom;
$infos['modification_type'] = 'A';
$infos['modification_type_1'] = '0';
$infos['modification_type_2'] = '0';
$infos['modification_type_3'] = '0';
$this->noms_stat['modification']++;
return $infos;
}
private function traiterDiffModif(&$nom, &$nom_precedent) {
$infos = array();
$nom_diff = array_diff_assoc($nom, $nom_precedent); $bdnt_partielle_tsv = 'trest';
if (count($nom_diff) > 0) {
$modif['modification_type'] = 'M';
$modif['modification_type_1'] = '0';
$modif['modification_type_2'] = '0';
$modif['modification_type_3'] = '0';
foreach ($this->champs_nom as $champ) {
if (isset($nom_diff[$champ])) {
$infos[$champ] = $nom_diff[$champ];
$type = $this->getDiffType($champ);
$modif['modification_type_'.$type] = '1';
} else {
if ($champ == 'num_nom') {
$infos[$champ] = $nom[$champ];
} else {
$infos[$champ] = '';
}
foreach ($modif as $cle => $val) {
$infos[$cle] = $val;
}
}
}
$infos = $this->remplacerTabulation($infos);
$infos = $this->remplacerSautsDeLigne($infos);
Debug::printr($infos);
Debug::printr("-------------------------------------------------");
$diff[$id][] = $infos;
if ($i == 100) break;
foreach ($modif as $cle => $val) {
$infos[$cle] = $val;
}
$this->noms_stat['modification']++;
}
return $diff;
return $infos;
}
private function chargerTableauChampsModifTypes() {
340,7 → 432,7
return $type;
}
private function ecrireFichierDiff($contenu) {
private function ecrireFichierDiff(&$contenu) {
$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_diff'];
$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
349,6 → 441,24
}
}
private function creerFichierDiffPartiel(&$donnees) {
if (count($donnees) > 0) {
$donnees['champs_partiel_diff'] = array_merge($this->champs_nom_partiel, $this->champs_diff);
$donnees['dernier_champ'] = end($donnees['champs_partiel_diff']);
$diff_tsv_partiel =& $this->getVue('versionnage/squelettes/diff_partiel', &$donnees, '.tpl.tsv');
$this->ecrireFichierDiffPartiel($diff_tsv_partiel);
}
}
private function ecrireFichierDiffPartiel(&$contenu) {
$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_diff'];
$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
if ($this->ecrireFichier($fichier_chemin, $contenu)) {
$this->ajouterMessage("Écriture du fichier diff partiel réussie.");
}
}
private function creerFichierMeta() {
$donnees = array();
$donnees = $this->meta;
358,40 → 468,33
$donnees = $this->remplacerTabulation($donnees);
$donnees = $this->remplacerSautsDeLigne($donnees);
$meta_tsv = $this->getVue('versionnage/squelettes/meta', $donnees, '.tpl.tsv');
$meta_tsv =& $this->getVue('versionnage/squelettes/meta', &$donnees, '.tpl.tsv');
$this->ecrireFichierMeta($meta_tsv);
return $donnees;
}
private function remplacerTabulation($doc) {
if (is_string($doc)) {
$doc = str_replace("\t", ' ', $doc);
} else if (is_array($doc) && count($doc) > 0) {
foreach ($doc as $cle => $valeur) {
$doc[$cle] = $this->remplacerTabulation($valeur);
}
private function ecrireFichierMeta(&$contenu) {
$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_meta'];
$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
if ($this->ecrireFichier($fichier_chemin, $contenu)) {
$this->ajouterMessage("Écriture du fichier meta réussie.");
$this->archiverMetadonnees();
}
return $doc;
}
private function remplacerSautsDeLigne($doc) {
if (is_string($doc)) {
$a_remplacer = array("\r", "\n");
$doc = str_replace($a_remplacer, ' ', $doc);
} else if (is_array($doc) && count($doc) > 0) {
foreach ($doc as $cle => $valeur) {
$doc[$cle] = $this->remplacerSautsDeLigne($valeur);
}
}
return $doc;
private function creerFichierMetaPartiel(&$donnees) {
$donnees['signature'] = $this->signature_md5_partiel;
$meta_tsv_partiel =& $this->getVue('versionnage/squelettes/meta', &$donnees, '.tpl.tsv');
$this->ecrireFichierMetaPartiel($meta_tsv_partiel);
}
private function ecrireFichierMeta($contenu) {
private function ecrireFichierMetaPartiel(&$contenu) {
$fichier_nom = $this->getBaseNomFichier().$this->manuel['ext_fichier_meta'];
$fichier_chemin = $this->zip_chemin_dossier.$fichier_nom;
$fichier_chemin = $this->zip_chemin_dossier_partiel.$fichier_nom;
if ($this->ecrireFichier($fichier_chemin, $contenu)) {
$this->ajouterMessage("Écriture du fichier meta réussie.");
$this->archiverMetadonnees();
$this->ajouterMessage("Écriture du fichier meta partiel réussie.");
}
}
426,36 → 529,31
private function copierManuel() {
$fichier_source = $this->manuel_chemin.$this->manuel_nom;
$fichier_destination = $this->zip_chemin_dossier.$this->manuel_nom;
if (copy($fichier_source, $fichier_destination) === false) {
$this->ajouterMessage("La copie du manuel '$fichier_destination' a échouée.");
$fichiers_destination[] = $this->zip_chemin_dossier.$this->manuel_nom;
$fichiers_destination[] = $this->zip_chemin_dossier_partiel.$this->manuel_nom;
foreach ($fichiers_destination as $destination) {
if (copy($fichier_source, $destination) === false) {
$this->ajouterMessage("La copie du manuel vers '$destination' a échouée.");
}
}
}
private function creerFichierZip() {
$fichierZip = new PclZip($this->zip_chemin_fichier);
if ($fichierZip->add($this->zip_chemin_dossier, PCLZIP_OPT_REMOVE_ALL_PATH) == 0) {
$e = "La création du fichier zip '$this->zip_chemin_fichier' a échoué avec l'erreur : ".$fichierZip->errorInfo(true);
private function creerFichiersZip() {
$this->zipper($this->zip_chemin_fichier, $this->zip_chemin_dossier);
$this->zipper($this->zip_chemin_fichier_partiel, $this->zip_chemin_dossier_partiel);
}
private function zipper($fichier_zip, $dossier_a_zipper) {
$zip = new PclZip($fichier_zip);
if ($zip->add($dossier_a_zipper, PCLZIP_OPT_REMOVE_ALL_PATH) == 0) {
$e = "La création du fichier zip '$fichier_zip' a échoué avec l'erreur : ".$zip->errorInfo(true);
$this->ajouterMessage($e);
}
}
}
private function nettoyerFichiers() {
$dossier = $this->zip_chemin_dossier;
if (is_dir($dossier)) {
$objets = scandir($dossier);
foreach ($objets as $objet) {
if ($objet != '.' && $objet != '..') {
if (filetype($dossier.'/'.$objet) == 'dir') {
rrmdir($dossier.'/'.$objet);
} else {
unlink($dossier.'/'.$objet);
}
}
}
reset($objets);
rmdir($dossier);
}
Fichier::supprimerDossier($this->zip_chemin_dossier);
Fichier::supprimerDossier($this->zip_chemin_dossier_partiel);
}
private function traiterMessages() {