|
@@ -545,7 +545,7 @@ EOF
|
|
* @param DateTime $oLastFullLoadStartDate Date of the last full load (start date/time), if known
|
|
* @param DateTime $oLastFullLoadStartDate Date of the last full load (start date/time), if known
|
|
* @return void
|
|
* @return void
|
|
*/
|
|
*/
|
|
- public function Synchronize(&$aTraces, $oLastFullLoadStartDate = null)
|
|
|
|
|
|
+ public function Synchronize($oLastFullLoadStartDate = null)
|
|
{
|
|
{
|
|
// Create a change used for logging all the modifications/creations happening during the synchro
|
|
// Create a change used for logging all the modifications/creations happening during the synchro
|
|
$oMyChange = MetaModel::NewObject("CMDBChange");
|
|
$oMyChange = MetaModel::NewObject("CMDBChange");
|
|
@@ -584,7 +584,7 @@ EOF
|
|
|
|
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- $this->DoSynchronize($oLastFullLoadStartDate, $oMyChange, $oStatLog, $aTraces);
|
|
|
|
|
|
+ $this->DoSynchronize($oLastFullLoadStartDate, $oMyChange, $oStatLog);
|
|
|
|
|
|
$oStatLog->Set('end_date', time());
|
|
$oStatLog->Set('end_date', time());
|
|
$oStatLog->Set('status', 'completed');
|
|
$oStatLog->Set('status', 'completed');
|
|
@@ -608,7 +608,7 @@ EOF
|
|
return $oStatLog;
|
|
return $oStatLog;
|
|
}
|
|
}
|
|
|
|
|
|
- protected function DoSynchronize($oLastFullLoadStartDate, $oMyChange, &$oStatLog, &$aTraces)
|
|
|
|
|
|
+ protected function DoSynchronize($oLastFullLoadStartDate, $oMyChange, &$oStatLog)
|
|
{
|
|
{
|
|
if ($this->Get('status') == 'obsolete')
|
|
if ($this->Get('status') == 'obsolete')
|
|
{
|
|
{
|
|
@@ -640,7 +640,7 @@ EOF
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$sLimitDate = $oLastFullLoadStartDate->Format('Y-m-d H:i:s');
|
|
$sLimitDate = $oLastFullLoadStartDate->Format('Y-m-d H:i:s');
|
|
- $aTraces[] = "Limit Date: $sLimitDate";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Limit Date: $sLimitDate");
|
|
$sSelectToObsolete = "SELECT SynchroReplica WHERE sync_source_id = :source_id AND status IN ('new', 'synchronized', 'modified', 'orphan') AND status_last_seen < :last_import";
|
|
$sSelectToObsolete = "SELECT SynchroReplica WHERE sync_source_id = :source_id AND status IN ('new', 'synchronized', 'modified', 'orphan') AND status_last_seen < :last_import";
|
|
$oSetToObsolete = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToObsolete), array() /* order by*/, array('source_id' => $this->GetKey(), 'last_import' => $sLimitDate));
|
|
$oSetToObsolete = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToObsolete), array() /* order by*/, array('source_id' => $this->GetKey(), 'last_import' => $sLimitDate));
|
|
if (($iCountAllReplicas > 10) && ($iCountAllReplicas == $oSetToObsolete->Count()))
|
|
if (($iCountAllReplicas > 10) && ($iCountAllReplicas == $oSetToObsolete->Count()))
|
|
@@ -653,7 +653,7 @@ EOF
|
|
{
|
|
{
|
|
case 'update':
|
|
case 'update':
|
|
case 'update_then_delete':
|
|
case 'update_then_delete':
|
|
- $aTraces[] = "Destination object: (dest_id:".$oReplica->Get('dest_id').") to be updated";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Destination object to be updated", $oReplica);
|
|
$aToUpdate = array();
|
|
$aToUpdate = array();
|
|
$aToUpdate = explode(';', $this->Get('delete_policy_update')); //ex: 'status:obsolete;description:stopped',
|
|
$aToUpdate = explode(';', $this->Get('delete_policy_update')); //ex: 'status:obsolete;description:stopped',
|
|
foreach($aToUpdate as $sUpdateSpec)
|
|
foreach($aToUpdate as $sUpdateSpec)
|
|
@@ -666,15 +666,15 @@ EOF
|
|
$aToUpdate[$sAttCode] = $sValue;
|
|
$aToUpdate[$sAttCode] = $sValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- $oReplica->UpdateDestObject($aToUpdate, $oMyChange, $oStatLog, $aTraces);
|
|
|
|
|
|
+ $oReplica->UpdateDestObject($aToUpdate, $oMyChange, $oStatLog);
|
|
$oReplica->Set('status', 'obsolete');
|
|
$oReplica->Set('status', 'obsolete');
|
|
$oReplica->DBUpdateTracked($oMyChange);
|
|
$oReplica->DBUpdateTracked($oMyChange);
|
|
break;
|
|
break;
|
|
|
|
|
|
case 'delete':
|
|
case 'delete':
|
|
default:
|
|
default:
|
|
- $aTraces[] = "Destination object: (dest_id:".$oReplica->Get('dest_id').") to be DELETED";
|
|
|
|
- $oReplica->DeleteDestObject($oMyChange, $oStatLog, $aTraces);
|
|
|
|
|
|
+ $oStatLog->AddTrace("Destination object to be DELETED", $oReplica);
|
|
|
|
+ $oReplica->DeleteDestObject($oMyChange, $oStatLog);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -724,8 +724,8 @@ EOF
|
|
$aReconciliationKeys = array("primary_key" => null);
|
|
$aReconciliationKeys = array("primary_key" => null);
|
|
}
|
|
}
|
|
|
|
|
|
- $aTraces[] = "Update of: {".implode(', ', array_keys($aAttCodesToUpdate))."}";
|
|
|
|
- $aTraces[] = "Reconciliation on: {".implode(', ', array_keys($aReconciliationKeys))."}";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Update of: {".implode(', ', array_keys($aAttCodesToUpdate))."}");
|
|
|
|
+ $oStatLog->AddTrace("Reconciliation on: {".implode(', ', array_keys($aReconciliationKeys))."}");
|
|
|
|
|
|
$aAttributes = array();
|
|
$aAttributes = array();
|
|
foreach($aAttCodesToUpdate as $sAttCode => $oSyncAtt)
|
|
foreach($aAttCodesToUpdate as $sAttCode => $oSyncAtt)
|
|
@@ -742,7 +742,7 @@ EOF
|
|
|
|
|
|
while($oReplica = $oSetToSync->Fetch())
|
|
while($oReplica = $oSetToSync->Fetch())
|
|
{
|
|
{
|
|
- $oReplica->Synchro($this, $aReconciliationKeys, $aAttributes, $oMyChange, $oStatLog, $aTraces);
|
|
|
|
|
|
+ $oReplica->Synchro($this, $aReconciliationKeys, $aAttributes, $oMyChange, $oStatLog);
|
|
}
|
|
}
|
|
|
|
|
|
// Get all the replicas that are to be deleted
|
|
// Get all the replicas that are to be deleted
|
|
@@ -757,13 +757,13 @@ EOF
|
|
$oDeletionDate->Modify($sInterval);
|
|
$oDeletionDate->Modify($sInterval);
|
|
}
|
|
}
|
|
$sDeletionDate = $oDeletionDate->Format('Y-m-d H:i:s');
|
|
$sDeletionDate = $oDeletionDate->Format('Y-m-d H:i:s');
|
|
- $aTraces[] = "Deletion date: $sDeletionDate";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Deletion date: $sDeletionDate");
|
|
$sSelectToDelete = "SELECT SynchroReplica WHERE sync_source_id = :source_id AND status IN ('obsolete') AND status_last_seen < :last_import";
|
|
$sSelectToDelete = "SELECT SynchroReplica WHERE sync_source_id = :source_id AND status IN ('obsolete') AND status_last_seen < :last_import";
|
|
$oSetToDelete = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToDelete), array() /* order by*/, array('source_id' => $this->GetKey(), 'last_import' => $sDeletionDate));
|
|
$oSetToDelete = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToDelete), array() /* order by*/, array('source_id' => $this->GetKey(), 'last_import' => $sDeletionDate));
|
|
while($oReplica = $oSetToDelete->Fetch())
|
|
while($oReplica = $oSetToDelete->Fetch())
|
|
{
|
|
{
|
|
- $aTraces[] = "Destination object: (dest_id:".$oReplica->Get('dest_id').") to be DELETED";
|
|
|
|
- $oReplica->DeleteDestObject($oMyChange, $oStatLog, $aTraces);
|
|
|
|
|
|
+ $oStatLog->AddTrace("Destination object to be DELETED", $oReplica);
|
|
|
|
+ $oReplica->DeleteDestObject($oMyChange, $oStatLog);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -998,10 +998,11 @@ class SynchroLog extends cmdbAbstractObject
|
|
MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_obj_new_unchanged", array("allowed_values"=>null, "sql"=>"stats_nb_obj_new_unchanged", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
|
|
MetaModel::Init_AddAttribute(new AttributeInteger("stats_nb_obj_new_unchanged", array("allowed_values"=>null, "sql"=>"stats_nb_obj_new_unchanged", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
|
|
|
|
|
|
MetaModel::Init_AddAttribute(new AttributeString("last_error", array("allowed_values"=>null, "sql"=>"last_error", "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array())));
|
|
MetaModel::Init_AddAttribute(new AttributeString("last_error", array("allowed_values"=>null, "sql"=>"last_error", "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array())));
|
|
|
|
+ MetaModel::Init_AddAttribute(new AttributeLongText("traces", array("allowed_values"=>null, "sql"=>"traces", "default_value"=>'', "is_null_allowed"=>true, "depends_on"=>array())));
|
|
|
|
|
|
// Display lists
|
|
// Display lists
|
|
MetaModel::Init_SetZListItems('details', array('sync_source_id', 'start_date', 'end_date', 'status', 'stats_nb_replica_total', 'stats_nb_replica_seen', 'stats_nb_obj_created', /*'stats_nb_replica_reconciled',*/ 'stats_nb_obj_updated', 'stats_nb_obj_obsoleted', 'stats_nb_obj_deleted',
|
|
MetaModel::Init_SetZListItems('details', array('sync_source_id', 'start_date', 'end_date', 'status', 'stats_nb_replica_total', 'stats_nb_replica_seen', 'stats_nb_obj_created', /*'stats_nb_replica_reconciled',*/ 'stats_nb_obj_updated', 'stats_nb_obj_obsoleted', 'stats_nb_obj_deleted',
|
|
- 'stats_nb_obj_created_errors', 'stats_nb_replica_reconciled_errors', 'stats_nb_replica_disappeared_no_action', 'stats_nb_obj_updated_errors', 'stats_nb_obj_obsoleted_errors', 'stats_nb_obj_deleted_errors', 'stats_nb_obj_new_unchanged', 'stats_nb_obj_new_updated')); // Attributes to be displayed for the complete details
|
|
|
|
|
|
+ 'stats_nb_obj_created_errors', 'stats_nb_replica_reconciled_errors', 'stats_nb_replica_disappeared_no_action', 'stats_nb_obj_updated_errors', 'stats_nb_obj_obsoleted_errors', 'stats_nb_obj_deleted_errors', 'stats_nb_obj_new_unchanged', 'stats_nb_obj_new_updated', 'dump')); // Attributes to be displayed for the complete details
|
|
MetaModel::Init_SetZListItems('list', array('sync_source_id', 'start_date', 'end_date', 'status', 'stats_nb_replica_seen')); // Attributes to be displayed for a list
|
|
MetaModel::Init_SetZListItems('list', array('sync_source_id', 'start_date', 'end_date', 'status', 'stats_nb_replica_seen')); // Attributes to be displayed for a list
|
|
// Search criteria
|
|
// Search criteria
|
|
// MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
|
|
// MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
|
|
@@ -1015,6 +1016,72 @@ class SynchroLog extends cmdbAbstractObject
|
|
{
|
|
{
|
|
$this->Set($sCode, 1+$this->Get($sCode));
|
|
$this->Set($sCode, 1+$this->Get($sCode));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Implement traces management
|
|
|
|
+ */
|
|
|
|
+ protected $m_aTraces = array();
|
|
|
|
+ public function AddTrace($sMsg, $oReplica = null)
|
|
|
|
+ {
|
|
|
|
+ if (MetaModel::GetConfig()->Get('synchro_trace') == 'none')
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($oReplica)
|
|
|
|
+ {
|
|
|
|
+ $sDestClass = $oReplica->Get('dest_class');
|
|
|
|
+ if (!empty($sDestClass))
|
|
|
|
+ {
|
|
|
|
+ $sPrefix = $oReplica->GetKey().','.$sDestClass.'::'.$oReplica->Get('dest_id').',';
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ $sPrefix = $oReplica->GetKey().',,';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ $sPrefix = ',,';
|
|
|
|
+ }
|
|
|
|
+ $this->m_aTraces[] = $sPrefix.$sMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function GetTraces()
|
|
|
|
+ {
|
|
|
|
+ return $this->m_aTraces;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function TraceToText()
|
|
|
|
+ {
|
|
|
|
+ if (MetaModel::GetConfig()->Get('synchro_trace') != 'save')
|
|
|
|
+ {
|
|
|
|
+ // none, or display only
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $oAttDef = MetaModel::GetAttributeDef(get_class($this), 'traces');
|
|
|
|
+ $iMaxSize = $oAttDef->GetMaxSize();
|
|
|
|
+ $sTrace = implode("\n", $this->m_aTraces);
|
|
|
|
+ if (strlen($sTrace) >= $iMaxSize)
|
|
|
|
+ {
|
|
|
|
+ $sTrace = substr($sTrace, 0, $iMaxSize - 255)."...\nTruncated (size: ".strlen($sTrace).')';
|
|
|
|
+ }
|
|
|
|
+ $this->Set('traces', $sTrace);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function OnInsert()
|
|
|
|
+ {
|
|
|
|
+ $this->TraceToText();
|
|
|
|
+ parent::OnInsert();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function OnUpdate()
|
|
|
|
+ {
|
|
|
|
+ $this->TraceToText();
|
|
|
|
+ parent::OnUpdate();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1097,7 +1164,7 @@ class SynchroReplica extends DBObject
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public function Synchro($oDataSource, $aReconciliationKeys, $aAttributes, $oChange, &$oStatLog, &$aTraces)
|
|
|
|
|
|
+ public function Synchro($oDataSource, $aReconciliationKeys, $aAttributes, $oChange, &$oStatLog)
|
|
{
|
|
{
|
|
switch($this->Get('status'))
|
|
switch($this->Get('status'))
|
|
{
|
|
{
|
|
@@ -1117,7 +1184,7 @@ class SynchroReplica extends DBObject
|
|
$aFilterValues = array();
|
|
$aFilterValues = array();
|
|
foreach($aReconciliationKeys as $sFilterCode => $oSyncAtt)
|
|
foreach($aReconciliationKeys as $sFilterCode => $oSyncAtt)
|
|
{
|
|
{
|
|
- $value = $this->GetValueFromExtData($sFilterCode, $oSyncAtt, $oStatLog, $aTraces);
|
|
|
|
|
|
+ $value = $this->GetValueFromExtData($sFilterCode, $oSyncAtt, $oStatLog);
|
|
if (!is_null($value))
|
|
if (!is_null($value))
|
|
{
|
|
{
|
|
$aFilterValues[$sFilterCode] = $value;
|
|
$aFilterValues[$sFilterCode] = $value;
|
|
@@ -1125,7 +1192,7 @@ class SynchroReplica extends DBObject
|
|
else
|
|
else
|
|
{
|
|
{
|
|
// Reconciliation could not be performed - log and EXIT
|
|
// Reconciliation could not be performed - log and EXIT
|
|
- $aTraces[] = "Could not reconcile on null value: ".$sFilterCode;
|
|
|
|
|
|
+ $oStatLog->AddTrace("Could not reconcile on null value: ".$sFilterCode, $this);
|
|
$this->SetLastError('Could not reconcile on null value: '.$sFilterCode);
|
|
$this->SetLastError('Could not reconcile on null value: '.$sFilterCode);
|
|
$oStatLog->Inc('stats_nb_replica_reconciled_errors');
|
|
$oStatLog->Inc('stats_nb_replica_reconciled_errors');
|
|
return;
|
|
return;
|
|
@@ -1143,54 +1210,54 @@ class SynchroReplica extends DBObject
|
|
switch($iCount)
|
|
switch($iCount)
|
|
{
|
|
{
|
|
case 0:
|
|
case 0:
|
|
- $aTraces[] = "Nothing found on: $sConditionDesc";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Nothing found on: $sConditionDesc", $this);
|
|
if ($oDataSource->Get('action_on_zero') == 'create')
|
|
if ($oDataSource->Get('action_on_zero') == 'create')
|
|
{
|
|
{
|
|
- $this->CreateObjectFromReplica($oDataSource->GetTargetClass(), $aAttributes, $oChange, $oStatLog, $aTraces);
|
|
|
|
|
|
+ $this->CreateObjectFromReplica($oDataSource->GetTargetClass(), $aAttributes, $oChange, $oStatLog);
|
|
}
|
|
}
|
|
else // assumed to be 'error'
|
|
else // assumed to be 'error'
|
|
{
|
|
{
|
|
- $aTraces[] = "Failed to reconcile (no match)";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Failed to reconcile (no match)", $this);
|
|
$this->SetLastError('Could not find a match for reconciliation');
|
|
$this->SetLastError('Could not find a match for reconciliation');
|
|
$oStatLog->Inc('stats_nb_replica_reconciled_errors');
|
|
$oStatLog->Inc('stats_nb_replica_reconciled_errors');
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
case 1:
|
|
case 1:
|
|
- $aTraces[] = "Found 1 object on: $sConditionDesc";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Found 1 object on: $sConditionDesc", $this);
|
|
if ($oDataSource->Get('action_on_one') == 'update')
|
|
if ($oDataSource->Get('action_on_one') == 'update')
|
|
{
|
|
{
|
|
$oDestObj = $oDestSet->Fetch();
|
|
$oDestObj = $oDestSet->Fetch();
|
|
- $this->UpdateObjectFromReplica($oDestObj, $aAttributes, $oChange, $oStatLog, $aTraces, 'stats_nb_obj_new', 'stats_nb_replica_reconciled_errors');
|
|
|
|
|
|
+ $this->UpdateObjectFromReplica($oDestObj, $aAttributes, $oChange, $oStatLog, 'stats_nb_obj_new', 'stats_nb_replica_reconciled_errors');
|
|
$this->Set('dest_id', $oDestObj->GetKey());
|
|
$this->Set('dest_id', $oDestObj->GetKey());
|
|
$this->Set('dest_class', get_class($oDestObj));
|
|
$this->Set('dest_class', get_class($oDestObj));
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
// assumed to be 'error'
|
|
// assumed to be 'error'
|
|
- $aTraces[] = "Failed to reconcile (1 match)";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Failed to reconcile (1 match)", $this);
|
|
$this->SetLastError('Found a match while expecting several');
|
|
$this->SetLastError('Found a match while expecting several');
|
|
$oStatLog->Inc('stats_nb_replica_reconciled_errors');
|
|
$oStatLog->Inc('stats_nb_replica_reconciled_errors');
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
default:
|
|
default:
|
|
- $aTraces[] = "Found $iCount objects on: $sConditionDesc";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Found $iCount objects on: $sConditionDesc", $this);
|
|
if ($oDataSource->Get('action_on_multiple') == 'error')
|
|
if ($oDataSource->Get('action_on_multiple') == 'error')
|
|
{
|
|
{
|
|
- $aTraces[] = "Failed to reconcile (N>1 matches)";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Failed to reconcile (N>1 matches)", $this);
|
|
$this->SetLastError($iCount.' destination objects match the reconciliation criterias: '.$sConditionDesc);
|
|
$this->SetLastError($iCount.' destination objects match the reconciliation criterias: '.$sConditionDesc);
|
|
$oStatLog->Inc('stats_nb_replica_reconciled_errors');
|
|
$oStatLog->Inc('stats_nb_replica_reconciled_errors');
|
|
}
|
|
}
|
|
elseif ($oDataSource->Get('action_on_multiple') == 'create')
|
|
elseif ($oDataSource->Get('action_on_multiple') == 'create')
|
|
{
|
|
{
|
|
- $this->CreateObjectFromReplica($oDataSource->GetTargetClass(), $aAttributes, $oChange, $oStatLog, $aTraces);
|
|
|
|
|
|
+ $this->CreateObjectFromReplica($oDataSource->GetTargetClass(), $aAttributes, $oChange, $oStatLog);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
// assumed to be 'take_first'
|
|
// assumed to be 'take_first'
|
|
$oDestObj = $oDestSet->Fetch();
|
|
$oDestObj = $oDestSet->Fetch();
|
|
- $this->UpdateObjectFromReplica($oDestObj, $aAttributes, $oChange, $oStatLog, $aTraces, 'stats_nb_obj_new', 'stats_nb_replica_reconciled_errors');
|
|
|
|
|
|
+ $this->UpdateObjectFromReplica($oDestObj, $aAttributes, $oChange, $oStatLog, 'stats_nb_obj_new', 'stats_nb_replica_reconciled_errors');
|
|
$this->Set('dest_id', $oDestObj->GetKey());
|
|
$this->Set('dest_id', $oDestObj->GetKey());
|
|
$this->Set('dest_class', get_class($oDestObj));
|
|
$this->Set('dest_class', get_class($oDestObj));
|
|
}
|
|
}
|
|
@@ -1207,7 +1274,7 @@ class SynchroReplica extends DBObject
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- $this->UpdateObjectFromReplica($oDestObj, $aAttributes, $oChange, $oStatLog, $aTraces, 'stats_nb_obj', 'stats_nb_obj_updated_errors');
|
|
|
|
|
|
+ $this->UpdateObjectFromReplica($oDestObj, $aAttributes, $oChange, $oStatLog, 'stats_nb_obj', 'stats_nb_obj_updated_errors');
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
@@ -1219,12 +1286,12 @@ class SynchroReplica extends DBObject
|
|
/**
|
|
/**
|
|
* Updates the destination object with the Extended data found in the synchro_data_XXXX table
|
|
* Updates the destination object with the Extended data found in the synchro_data_XXXX table
|
|
*/
|
|
*/
|
|
- protected function UpdateObjectFromReplica($oDestObj, $aAttributes, $oChange, &$oStatLog, &$aTraces, $sStatsCode, $sStatsCodeError)
|
|
|
|
|
|
+ protected function UpdateObjectFromReplica($oDestObj, $aAttributes, $oChange, &$oStatLog, $sStatsCode, $sStatsCodeError)
|
|
{
|
|
{
|
|
$aValueTrace = array();
|
|
$aValueTrace = array();
|
|
foreach($aAttributes as $sAttCode => $oSyncAtt)
|
|
foreach($aAttributes as $sAttCode => $oSyncAtt)
|
|
{
|
|
{
|
|
- $value = $this->GetValueFromExtData($sAttCode, $oSyncAtt, $oStatLog, $aTraces);
|
|
|
|
|
|
+ $value = $this->GetValueFromExtData($sAttCode, $oSyncAtt, $oStatLog);
|
|
if (!is_null($value))
|
|
if (!is_null($value))
|
|
{
|
|
{
|
|
$oDestObj->Set($sAttCode, $value);
|
|
$oDestObj->Set($sAttCode, $value);
|
|
@@ -1237,12 +1304,12 @@ class SynchroReplica extends DBObject
|
|
if ($oDestObj->IsModified())
|
|
if ($oDestObj->IsModified())
|
|
{
|
|
{
|
|
$oDestObj->DBUpdateTracked($oChange);
|
|
$oDestObj->DBUpdateTracked($oChange);
|
|
- $aTraces[] = "Updated object ".$oDestObj->GetHyperLink()." (".implode(', ', $aValueTrace).")";
|
|
|
|
|
|
+ $oStatLog->AddTrace('Updated object - Values: {'.implode(', ', $aValueTrace).'}', $this);
|
|
$oStatLog->Inc($sStatsCode.'_updated');
|
|
$oStatLog->Inc($sStatsCode.'_updated');
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- $aTraces[] = "Unchanged object ".$oDestObj->GetHyperLink()." (".implode(', ', $aValueTrace).")";
|
|
|
|
|
|
+ $oStatLog->AddTrace('Unchanged object', $this);
|
|
$oStatLog->Inc($sStatsCode.'_unchanged');
|
|
$oStatLog->Inc($sStatsCode.'_unchanged');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1251,7 +1318,7 @@ class SynchroReplica extends DBObject
|
|
}
|
|
}
|
|
catch(Exception $e)
|
|
catch(Exception $e)
|
|
{
|
|
{
|
|
- $aTraces[] = "Failed to update destination object: {$e->getMessage()}";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Failed to update destination object: {$e->getMessage()}", $this);
|
|
$this->SetLastError('Unable to update destination object: ', $e);
|
|
$this->SetLastError('Unable to update destination object: ', $e);
|
|
$oStatLog->Inc($sStatsCodeError);
|
|
$oStatLog->Inc($sStatsCodeError);
|
|
}
|
|
}
|
|
@@ -1260,7 +1327,7 @@ class SynchroReplica extends DBObject
|
|
/**
|
|
/**
|
|
* Creates the destination object populating it with the Extended data found in the synchro_data_XXXX table
|
|
* Creates the destination object populating it with the Extended data found in the synchro_data_XXXX table
|
|
*/
|
|
*/
|
|
- protected function CreateObjectFromReplica($sClass, $aAttributes, $oChange, &$oStatLog, &$aTraces)
|
|
|
|
|
|
+ protected function CreateObjectFromReplica($sClass, $aAttributes, $oChange, &$oStatLog)
|
|
{
|
|
{
|
|
$oDestObj = MetaModel::NewObject($sClass);
|
|
$oDestObj = MetaModel::NewObject($sClass);
|
|
try
|
|
try
|
|
@@ -1268,7 +1335,7 @@ class SynchroReplica extends DBObject
|
|
$aValueTrace = array();
|
|
$aValueTrace = array();
|
|
foreach($aAttributes as $sAttCode => $oSyncAtt)
|
|
foreach($aAttributes as $sAttCode => $oSyncAtt)
|
|
{
|
|
{
|
|
- $value = $this->GetValueFromExtData($sAttCode, $oSyncAtt, $oStatLog, $aTraces);
|
|
|
|
|
|
+ $value = $this->GetValueFromExtData($sAttCode, $oSyncAtt, $oStatLog);
|
|
if (!is_null($value))
|
|
if (!is_null($value))
|
|
{
|
|
{
|
|
$oDestObj->Set($sAttCode, $value);
|
|
$oDestObj->Set($sAttCode, $value);
|
|
@@ -1276,7 +1343,6 @@ class SynchroReplica extends DBObject
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$iNew = $oDestObj->DBInsertTracked($oChange);
|
|
$iNew = $oDestObj->DBInsertTracked($oChange);
|
|
- $aTraces[] = "Created $sClass::$iNew (".implode(', ', $aValueTrace).")";
|
|
|
|
|
|
|
|
$this->Set('dest_id', $oDestObj->GetKey());
|
|
$this->Set('dest_id', $oDestObj->GetKey());
|
|
$this->Set('dest_class', get_class($oDestObj));
|
|
$this->Set('dest_class', get_class($oDestObj));
|
|
@@ -1284,11 +1350,12 @@ class SynchroReplica extends DBObject
|
|
$this->Set('status_last_error', '');
|
|
$this->Set('status_last_error', '');
|
|
$this->Set('status', 'synchronized');
|
|
$this->Set('status', 'synchronized');
|
|
|
|
|
|
|
|
+ $oStatLog->AddTrace("Created (".implode(', ', $aValueTrace).")", $this);
|
|
$oStatLog->Inc('stats_nb_obj_created');
|
|
$oStatLog->Inc('stats_nb_obj_created');
|
|
}
|
|
}
|
|
catch(Exception $e)
|
|
catch(Exception $e)
|
|
{
|
|
{
|
|
- $aTraces[] = "Failed to create $sClass ({$e->getMessage()})";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Failed to create $sClass ({$e->getMessage()})", $this);
|
|
$this->SetLastError('Unable to create destination object: ', $e);
|
|
$this->SetLastError('Unable to create destination object: ', $e);
|
|
$oStatLog->Inc('stats_nb_obj_created_errors');
|
|
$oStatLog->Inc('stats_nb_obj_created_errors');
|
|
}
|
|
}
|
|
@@ -1297,7 +1364,7 @@ class SynchroReplica extends DBObject
|
|
/**
|
|
/**
|
|
* Update the destination object with given values
|
|
* Update the destination object with given values
|
|
*/
|
|
*/
|
|
- public function UpdateDestObject($aValues, $oChange, &$oStatLog, &$aTraces)
|
|
|
|
|
|
+ public function UpdateDestObject($aValues, $oChange, &$oStatLog)
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
@@ -1314,7 +1381,7 @@ class SynchroReplica extends DBObject
|
|
$oDestObj->Set($sAttCode, $value);
|
|
$oDestObj->Set($sAttCode, $value);
|
|
}
|
|
}
|
|
$oDestObj->DBUpdateTracked($oChange);
|
|
$oDestObj->DBUpdateTracked($oChange);
|
|
- $aTraces[] = "Replica id:".$this->GetKey()." (dest_id:".$this->Get('dest_id').") marked as obsolete";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Replica marked as obsolete", $this);
|
|
$oStatLog->Inc('stats_nb_obj_obsoleted');
|
|
$oStatLog->Inc('stats_nb_obj_obsoleted');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1328,7 +1395,7 @@ class SynchroReplica extends DBObject
|
|
/**
|
|
/**
|
|
* Delete the destination object
|
|
* Delete the destination object
|
|
*/
|
|
*/
|
|
- public function DeleteDestObject($oChange, &$oStatLog, &$aTraces)
|
|
|
|
|
|
+ public function DeleteDestObject($oChange, &$oStatLog)
|
|
{
|
|
{
|
|
if($this->Get('status_dest_creator'))
|
|
if($this->Get('status_dest_creator'))
|
|
{
|
|
{
|
|
@@ -1357,7 +1424,7 @@ class SynchroReplica extends DBObject
|
|
/**
|
|
/**
|
|
* Get the value from the 'Extended Data' located in the synchro_data_xxx table for this replica
|
|
* Get the value from the 'Extended Data' located in the synchro_data_xxx table for this replica
|
|
*/
|
|
*/
|
|
- protected function GetValueFromExtData($sColumnName, $oSyncAtt, &$oStatLog, &$aTraces)
|
|
|
|
|
|
+ protected function GetValueFromExtData($sColumnName, $oSyncAtt, &$oStatLog)
|
|
{
|
|
{
|
|
// $aData should contain attributes defined either for reconciliation or create/update
|
|
// $aData should contain attributes defined either for reconciliation or create/update
|
|
$aData = $this->GetExtendedData();
|
|
$aData = $this->GetExtendedData();
|
|
@@ -1386,7 +1453,7 @@ class SynchroReplica extends DBObject
|
|
else
|
|
else
|
|
{
|
|
{
|
|
// Note: differs from null (in which case the value would be left unchanged)
|
|
// Note: differs from null (in which case the value would be left unchanged)
|
|
- $aTraces[] = "Could not find [unique] object for '$sColumnName': searched on $sReconcAttCode = '$aData[$sColumnName]'";
|
|
|
|
|
|
+ $oStatLog->AddTrace("Could not find [unique] object for '$sColumnName': searched on $sReconcAttCode = '$aData[$sColumnName]'", $this);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|