diff --git a/synchro/synchrodatasource.class.inc.php b/synchro/synchrodatasource.class.inc.php index 605a86961..63a2fff4c 100644 --- a/synchro/synchrodatasource.class.inc.php +++ b/synchro/synchrodatasource.class.inc.php @@ -1,5 +1,5 @@ GetDataTable(); foreach($this->ListTargetAttributes() as $sAttCode=>$oAttDef) { if (!isset($aAttributes[$sAttCode])) @@ -845,8 +846,48 @@ EOF $oAttribute->DBInsertTracked($oChange); } } + else + { + $aColumns = $this->GetSQLColumns(array($sAttCode)); + foreach($aColumns as $sColName => $sColumnDef) + { + $bOneColIsMissing = false; + if (!CMDBSource::IsField($sTable, $sColName)) + { + $bFixNeeded = true; + $bOneColIsMissing = true; + if ($bVerbose) + { + if (count($aColumns) > 1) + { + echo "Missing column '$sColName', in the table '$sTable' for the data synchro task ".$this->GetName()." (".$this->GetKey()."). The columns '".implode("', '", $aColumns )." will be re-created.'.\n"; + } + else + { + echo "Missing column '$sColName', in the table '$sTable' for the data synchro task ".$this->GetName()." (".$this->GetKey()."). The column '$sColName' will be added.\n"; + } + } + } + else if (strcasecmp(CMDBSource::GetFieldType($sTable, $sColName), $sColumnDef) != 0) + { + $bFixNeeded = true; + $bOneColIsMissing = true; + if (count($aColumns) > 1) + { + echo "Incorrect column '$sColName' (".CMDBSource::GetFieldType($sTable, $sColName)." instead of ".$sColumnDef."), in the table '$sTable' for the data synchro task ".$this->GetName()." (".$this->GetKey()."). The columns '".implode("', '", $aColumns )." will be re-created.'.\n"; + } + else + { + echo "Incorrect column '$sColName' (".CMDBSource::GetFieldType($sTable, $sColName)." instead of ".$sColumnDef."), in the table '$sTable' for the data synchro task ".$this->GetName()." (".$this->GetKey()."). The column '$sColName' will be added.\n"; + } + } + if ($bOneColIsMissing) + { + $aMissingFields[] = $sAttCode; + } + } + } } - $sTable = $this->GetDataTable(); if ($bFixNeeded && (count($aMissingFields) > 0)) { $aRepairQueries = array(); @@ -880,7 +921,7 @@ EOF if ($bVerbose) { // Report the issue - echo "The structure of the table $sTable for the data synchro task ".$this->GetName()." (".$this->GetKey().") must be altered (missing fields: ".implode(',', $aMissingFields).").\n"; + echo "The structure of the table $sTable for the data synchro task ".$this->GetName()." (".$this->GetKey().") must be altered (missing or incorrect fields: ".implode(',', $aMissingFields).").\n"; echo "The trigger {$sTable}_bi, {$sTable}_bu, {$sTable}_ad for the data synchro task ".$this->GetName()." (".$this->GetKey().") must be re-created.\n"; echo implode("\n", $aRepairQueries)."\n"; } @@ -989,7 +1030,7 @@ EOF if ($oAttDef->IsExternalKey()) { // The pkey might be used as well as any other key column - $aColumns[$sAttCode] = 'VARCHAR (255)'; + $aColumns[$sAttCode] = 'VARCHAR(255)'; } else {