Problème MAJ données

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Problème MAJ données

Problème MAJ données

par popo79pr » 25 mars 2013, 16:44

++ Logiciel tier : GCE

Bonjour !

Lourd problème a régler rapidement !

1) Mon travail

Mettre à jour ma base de données Outils avec les données de la base de données du logiciel GCE

2) Initialisation

C'est le code (php) qui est exécuté quand la remise à zéro de ma base Outils est faite (en général, ce code ne sera utilisé qu'une fois)

Aucun problème ici : tout rentre bien dans ma base de données Outils (je ne met pas le code car trop long)

3) Structure de la bdd

Vous en aurez surement besoin pour m'aider :)
CREATE TABLE `infos` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `libelle` varchar(45) DEFAULT NULL,
  `Date_Debut` timestamp NULL DEFAULT NULL,
  `Date_Fin` timestamp NULL DEFAULT NULL,
  `Duree` int(11) DEFAULT NULL,
  `Statut` varchar(15) DEFAULT NULL,
  `Logiciel` int(11) DEFAULT NULL,
  `Code_Erreur` text,
  `Projet` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `ID_UNIQUE` (`ID`),
  KEY `Logiciels_idx` (`Logiciel`),
  KEY `Projets_idx` (`Projet`),
  CONSTRAINT `Logiciels` FOREIGN KEY (`Logiciel`) REFERENCES `logiciels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `Projets` FOREIGN KEY (`Projet`) REFERENCES `projets` (`idProjets`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=9882 DEFAULT CHARSET=utf8$$

CREATE TABLE `infos_complementaires` 
(
  `IDInfosComplementaires` int(11) NOT NULL AUTO_INCREMENT,
  `NumLibelle` int(11) DEFAULT NULL,
  `Valeur` varchar(255) DEFAULT NULL,
  `ID_Logs` int(11) DEFAULT NULL,
  PRIMARY KEY (`IDInfosComplementaires`),
  UNIQUE KEY `IDInfosComplémentaires_UNIQUE` (`NumLibelle`,`ID_Logs`),
  KEY `InfosLibellé_idx` (`NumLibelle`),
  KEY `ID_Logs_idx` (`ID_Logs`),
  CONSTRAINT `ID_Logs` FOREIGN KEY (`ID_Logs`) REFERENCES `infos` (`ID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `InfosLibellé` FOREIGN KEY (`NumLibelle`) REFERENCES `infoslibelle` (`IdLibelle`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=4530 DEFAULT CHARSET=utf8$$
CREATE TABLE `projets` 
(
  `idProjets` int(11) NOT NULL AUTO_INCREMENT,
  `NomProjet` varchar(45) DEFAULT NULL,
  `NumLogiciel` int(11) DEFAULT NULL,
  PRIMARY KEY (`idProjets`),
  UNIQUE KEY `idProjets_UNIQUE` (`idProjets`),
  KEY `Logiciel_idx` (`NumLogiciel`),
  CONSTRAINT `Logiciel` FOREIGN KEY (`NumLogiciel`) REFERENCES `logiciels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=utf8$$
CREATE TABLE `projets` 
(
  `idProjets` int(11) NOT NULL AUTO_INCREMENT,
  `NomProjet` varchar(45) DEFAULT NULL,
  `NumLogiciel` int(11) DEFAULT NULL,
  PRIMARY KEY (`idProjets`),
  UNIQUE KEY `idProjets_UNIQUE` (`idProjets`),
  KEY `Logiciel_idx` (`NumLogiciel`),
  CONSTRAINT `Logiciel` FOREIGN KEY (`NumLogiciel`) REFERENCES `logiciels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=utf8$$


4) Le code, le problème ...

Ensuite, toute les minutes (tache cron) je créé une mise à jour de la bdd Outils par rapport à celle de GCE.
Ca fonctionne, mais pas tout le temps il faut croire ... car j'obtiens des mises à jour bizarre
En fait, c'est une mise à jour régulière car certaines procédures (dans Infos) ont un statut 3 (voir plus bas dans mon post) ... puis après 1 minute le statut devient un statut 5 ou 1 (ou autre).

Sauf qu'à la mise à jour ça ne change pas ! ou pas sur toutes ...
/**
 * \brief	 Mise à jour
 * \details  Mise à jour des informations
			 en évitant les doubles ajouts
 */
 function MAJ()
{
	global $bddGCE;
	global $bddOutils;
	$logiciel = 2;
	$nbreInsertionUpdate = "0";
	$nbreInsertionUpdateFonctions = "0";
	$nbreInsertion = "0";
	$nbreInsertionFonctions = "0";
	
	// Logs début MAJ
	logs("Debut MAJ GCE","Demarrage des MAJ");	
	 
	 // Sélection des lignes dont la date est supérieure à J-1
	$stid = oci_parse($bddGCE, "SELECT nomprc, (select min(datdeb) from ut_spl where ut_spl.nomprc=ut_prc.nomprc and ut_spl.ESHS='ES' and ut_prc.codsoc=ut_spl.codsoc) as datdeb, 
	(select max(heufin) from ut_spl where ut_spl.nomprc=ut_prc.nomprc and ut_spl.ESHS='ES' and ut_spl.datfin = (select max(datfin) from ut_spl where ut_spl.nomprc=ut_prc.nomprc and ut_spl.ESHS='ES' and ut_prc.codsoc=ut_spl.codsoc) and ut_prc.codsoc=ut_spl.codsoc) as heufin,
	(select max(datfin) from ut_spl where ut_spl.nomprc=ut_prc.nomprc and ut_spl.ESHS='ES' and ut_prc.codsoc=ut_spl.codsoc) as datfin,
	st1, batch , (select min(heudeb) from ut_spl where ut_spl.nomprc=ut_prc.nomprc and ut_spl.ESHS='ES' and ut_spl.datfin = (select min(datfin) from ut_spl where ut_spl.nomprc=ut_prc.nomprc and ut_spl.ESHS='ES' and ut_prc.codsoc=ut_spl.codsoc) and ut_prc.codsoc=ut_spl.codsoc) as heudmd, codsoc, automanu, uti
	FROM ut_prc where (select min(datdeb) from ut_spl where ut_spl.nomprc=ut_prc.nomprc and ut_spl.ESHS='ES' and ut_prc.codsoc=ut_spl.codsoc)>=to_char(SYSDATE-1,'yyyymmdd')  and datdmd > '20130301' ");
	oci_execute($stid); 
	
	while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) 
		{
			$valeur="";
			foreach ($row as $item)
			{
				$valeur = $valeur . ($item !== null ? htmlentities($item, ENT_QUOTES) : "") . "/";
			}
			$init2 = explode("/", $valeur);
			$libellef = $init2[0]; 
			$dateDebutf = date('Y-m-d H:i:00',strtotime($init2[1] .' ' .$init2[6]));
			$dateFinf = date('Y-m-d H:i:00',strtotime($init2[3] .' ' .$init2[2]));
			$statutf = $init2[4]; 
			$projetf = $init2[5];
			$codeErreurf = '';
			$logiciel = "GCE";
			
			$automanu = $init2[8];
			$uti = $init2[9];
			
			// Comparaison avec la table Outils					
			$comparaison=$bddOutils->query("SELECT infos.libelle, date_debut, date_fin, duree, statut, projet, logiciel, code_erreur
			FROM infos, infos_complementaires, infoslibelle
			where infos.libelle = '".$libellef."'
			and infos.date_debut = '".$dateDebutf."'
			and (infos.Date_Fin != '".$dateFinf."' or infos.statut!='".$statutf."')
			and infos.id = infos_complementaires.id_logs
			and infos_complementaires.numlibelle = infoslibelle.idlibelle
			and infoslibelle.libelle = 'BU'
			and infos_complementaires.valeur = '".$init2[7]."'") or die(logs("Erreur comparaison MAJ gce et outils",str_replace("'"," ",($bddOutils->errorInfo())))) ;
			$comparaisonLIGNE = $comparaison->fetch();
			$comparaison->closeCursor();
			
			// Calcul de la durée (dateFin - DateDebut)
				$timestampDebut2 =strtotime($dateDebutf);
				$timestampFin2 =strtotime($dateFinf);
				$dureef2 = $timestampFin2 -  $timestampDebut2; // nombre de secondes d'intervalle entre les deux dates
			
			if ($comparaisonLIGNE[0]!='') // Si au moins un résultat est renvoyé, alors on modifie
			{	
				// procedure
				Update($dateFinf,$libellef,$dateDebutf,$comparaisonLIGNE[5],$comparaisonLIGNE[6],$comparaisonLIGNE[7],$statutf,$dureef2); 
				
				// fonctions
				$stid3 = oci_parse($bddGCE, "SELECT fct, datdeb, heudeb, datfin, heufin, st1, batch, codsoc, numero, tfc FROM ut_spl where nomprc ='".$libellef."' and ESHS='ES' and codsoc = '".$init2[7]."'");
				oci_execute($stid3); 
				while ($row2 = oci_fetch_array($stid3, OCI_ASSOC+OCI_RETURN_NULLS)) 
				{
					$valeur2="";
					foreach ($row2 as $item2)
					{
						$valeur2 = $valeur2 . ($item2 !== null ? htmlentities($item2, ENT_QUOTES) : "") . "/";
					}
					$init2 = explode("/", $valeur2);
					$libellefonction = $init2[0]; 
					$dateDebutfonction = date('Y-m-d H:i:00',strtotime($init2[1] .' ' .$init2[2]));
					$dateFinfonction = date('Y-m-d H:i:00',strtotime($init2[3] .' ' .$init2[4]));
					$statutffonction = $init2[5]; //st1

					// Calcul de la durée (dateFin - DateDebut)
					$timestampDebutfonction =strtotime($dateDebutfonction);
					$timestampFinfonction =strtotime($dateFinfonction);
					$dureeffonction = $timestampFinfonction -  $timestampDebutfonction; // nombre de secondes d'intervalle entre les deux dates
					
					$projetffonction = $init2[6];
					$codeErreurffonction = '';
					
					// Modification dans la table Infos
					Update($dateFinfonction,$libellefonction,$dateDebutfonction,$projetffonction,$logiciel,$codeErreurffonction,$statutffonction,$dureeffonction); 
					$nbreInsertionUpdateFonctions++;
				}
				
				$nbreInsertionUpdate++;
			}
			else // sinon on insert une nouvelle ligne
			{
				$comparaison2=$bddOutils->query("SELECT infos.libelle, date_debut, date_fin, duree, statut, projet, logiciel, code_erreur
				FROM infos, infos_complementaires, infoslibelle
				where infos.libelle = '".$libellef."'
				and infos.date_debut = '".$dateDebutf."'
				and infos.id = infos_complementaires.id_logs
				and infos_complementaires.numlibelle = infoslibelle.idlibelle
				and infoslibelle.libelle = 'BU'
				and infos_complementaires.valeur = '".$init2[7]."'") or die(logs("Erreur comparaison 2 MAJ gce et outils",str_replace("'"," ",($bddOutils->errorInfo())))) ;
				$comparaisonLIGNE2 = $comparaison2->fetch();
				$comparaison2->closeCursor();
				
				if ($comparaisonLIGNE2[0]=='')
				{
					// procedure
					insertionInfos($libellef, $dateDebutf,$dateFinf,$dureef2,$statutf,$logiciel,$codeErreurf,$projetf, $bddOutils); 
					$nbreInsertion++;

					// Recherche l'id
					$rechercheID=$bddOutils->query("SELECT LAST_INSERT_ID() FROM infos") or die(logs("Erreur Recherche ID procedures(compl. Infos)",str_replace("'"," ",($bddOutils->errorInfo())))) ;
					$rechercheIDLIGNE = $rechercheID->fetch();
					$id_logs = $rechercheIDLIGNE[0];
					$rechercheID->closeCursor();
					
					// Infos complémentaires
					insertionComplementsInfos($bddOutils,"Description","Procedure",$id_logs);
					insertionComplementsInfos($bddOutils,"BU",$init2[7], $id_logs);
					insertionComplementsInfos($bddOutils,"automanu",$automanu, $id_logs);
					insertionComplementsInfos($bddOutils,"user",$uti, $id_logs);
					
					// --- FONCTIONS ---
					$stid4 = oci_parse($bddGCE, "SELECT fct, datdeb, heudeb, datfin, heufin, st1, batch, codsoc, numero, tfc FROM ut_spl where nomprc ='".$libellef."' and ESHS='ES' and codsoc = '".$init2[7]."'");
					oci_execute($stid4); 
					while ($row4 = oci_fetch_array($stid4, OCI_ASSOC+OCI_RETURN_NULLS)) 
					{
						$valeur4="";
						foreach ($row4 as $item4)
						{
							$valeur4 = $valeur4 . ($item4 !== null ? htmlentities($item4, ENT_QUOTES) : "") . "/";
						}
						$init4 = explode("/", $valeur4);
						$libellefonction = $init4[0]; 
						$dateDebutfonction = date('Y-m-d H:i:00',strtotime($init4[1] .' ' .$init4[2]));
						$dateFinfonction = date('Y-m-d H:i:00',strtotime($init4[3] .' ' .$init4[4]));
						$statutffonction = $init4[5]; //st1

						// Calcul de la durée (dateFin - DateDebut)
						$timestampDebutfonction =strtotime($dateDebutfonction);
						$timestampFinfonction =strtotime($dateFinfonction);
						$dureeffonction = $timestampFinfonction -  $timestampDebutfonction; // nombre de secondes d'intervalle entre les deux dates
						
						$projetffonction = $init4[6];
						$codeErreurffonction = '';
						
						// Insertion dans la table Infos
						insertionInfos($libellefonction, $dateDebutfonction,$dateFinfonction,$dureeffonction,$statutffonction,$logiciel,$codeErreurffonction,$projetffonction, $bddOutils); 
						$nbreInsertionFonctions++;
						
						// Recherche l'id
						$rechercheIDFonctions=$bddOutils->query("SELECT LAST_INSERT_ID() FROM infos") or die(logs("Erreur Recherche ID fonctions (compl. Infos)",str_replace("'"," ",($bddOutils->errorInfo())))) ;
						$rechercheIDLIGNEFonctions = $rechercheIDFonctions->fetch();
						$id_logsFonctions = $rechercheIDLIGNEFonctions[0];
						$rechercheIDFonctions->closeCursor();
						
						// Infos complémentaires
						insertionComplementsInfos($bddOutils,"Description","Fonction",$id_logsFonctions);
						insertionComplementsInfos($bddOutils,"BU",$init2[7], $id_logsFonctions);
						insertionComplementsInfos($bddOutils,"NomFonction",$init2[9], $id_logsFonctions);
						insertionComplementsInfos($bddOutils,"NumeroFonction",$init2[8], $id_logsFonctions);
						insertionComplementsInfos($bddOutils,"idProcedure",$id_logs, $id_logsFonctions);
					}
				}
			}
		}

	logs("Fin MAJ GCE","UPDATE procedures : " . $nbreInsertionUpdate . " | UPDATE fonctions : " . $nbreInsertionUpdateFonctions . " | INSERTIONS procedures : " . $nbreInsertion . " | INSERTIONS fonctions : " . $nbreInsertionFonctions);

}
(code de la mise à jour)

Si questions n'hésitez pas, j'ai pas tout mis mais bon lol

Et je n'ai aucune erreur !

Juste mes données qui ne s'actualisent pas --'

Une erreur idiote sans doute.

Bisous !!!

Les statuts
1 : en attente
2 : en cours
3 : en cours
4 : terminé
5 : erreur