From 169bf4948b1d927daad8b6df08961b75a2847a20 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Tue, 15 Nov 2011 09:29:07 +0000 Subject: [PATCH] Data sync: fixed issue when a replica left in state 'new' becomes obsolete SVN:trunk[1668] --- synchro/synchro_import.php | 10 +++++++++- synchro/synchrodatasource.class.inc.php | 21 ++++++++++++++++----- test/testlist.inc.php | 5 +++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/synchro/synchro_import.php b/synchro/synchro_import.php index 781265dc8..f3a33b333 100644 --- a/synchro/synchro_import.php +++ b/synchro/synchro_import.php @@ -223,6 +223,14 @@ function ChangeDateFormat($sProposedDate, $sDateFormat) } +class CLILikeWebPage extends WebPage +{ + public function add_comment($sText) + { + $this->add('#'.$sText."
\n"); + } +} + ///////////////////////////////// // Main program @@ -232,7 +240,7 @@ if (utils::IsModeCLI()) } else { - $oP = new WebPage(Dict::S("TitleSynchroExecution")); + $oP = new CLILikeWebPage(Dict::S("TitleSynchroExecution")); } try diff --git a/synchro/synchrodatasource.class.inc.php b/synchro/synchrodatasource.class.inc.php index ca374afeb..b569f090a 100644 --- a/synchro/synchrodatasource.class.inc.php +++ b/synchro/synchrodatasource.class.inc.php @@ -1158,11 +1158,19 @@ EOF } } $oReplica->Set('status_last_error', ''); - $oReplica->UpdateDestObject($aToUpdate, $oMyChange, $oStatLog); - if ($oReplica->Get('status_last_error') == '') + if ($oReplica->Get('dest_id') == '') { - // Change the status of the replica IIF $oReplica->Set('status', 'obsolete'); + $oStatLog->Inc('stats_nb_replica_disappeared_no_action'); + } + else + { + $oReplica->UpdateDestObject($aToUpdate, $oMyChange, $oStatLog); + if ($oReplica->Get('status_last_error') == '') + { + // Change the status of the replica IIF + $oReplica->Set('status', 'obsolete'); + } } $oReplica->DBUpdateTracked($oMyChange); break; @@ -1182,8 +1190,8 @@ EOF // Get all the replicas that are 'new' or modified // - $sSelectToSync = "SELECT SynchroReplica WHERE (status = 'new' OR status = 'modified') AND sync_source_id = :source_id"; - $oSetToSync = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToSync), array() /* order by*/, array('source_id' => $this->GetKey()) /* aArgs */, $aExtDataSpec, 0 /* limitCount */, 0 /* limitStart */); + $sSelectToSync = "SELECT SynchroReplica WHERE (status = 'new' OR status = 'modified') AND sync_source_id = :source_id AND status_last_seen >= :last_import"; + $oSetToSync = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToSync), array() /* order by*/, array('source_id' => $this->GetKey(), 'last_import' => $sLimitDate) /* aArgs */, $aExtDataSpec, 0 /* limitCount */, 0 /* limitStart */); while($oReplica = $oSetToSync->Fetch()) { @@ -1741,6 +1749,7 @@ class SynchroReplica extends DBObject implements iDisplay else // assumed to be 'error' { $oStatLog->AddTrace("Failed to reconcile (no match)", $this); + // Recoverable error $this->SetLastError('Could not find a match for reconciliation'); $oStatLog->Inc('stats_nb_replica_reconciled_errors'); } @@ -1759,6 +1768,7 @@ class SynchroReplica extends DBObject implements iDisplay { // assumed to be 'error' $oStatLog->AddTrace("Failed to reconcile (1 match)", $this); + // Recoverable error $this->SetLastError('Found a match while expecting several'); $oStatLog->Inc('stats_nb_replica_reconciled_errors'); } @@ -1769,6 +1779,7 @@ class SynchroReplica extends DBObject implements iDisplay if ($oDataSource->Get('action_on_multiple') == 'error') { $oStatLog->AddTrace("Failed to reconcile (N>1 matches)", $this); + // Recoverable error $this->SetLastError($iCount.' destination objects match the reconciliation criterias: '.$sConditionDesc); $oStatLog->Inc('stats_nb_replica_reconciled_errors'); } diff --git a/test/testlist.inc.php b/test/testlist.inc.php index 55c9f8936..38022fde3 100644 --- a/test/testlist.inc.php +++ b/test/testlist.inc.php @@ -1999,6 +1999,7 @@ class TestDataExchange extends TestBizModel foreach($aTargetData as $iRow => $aExpectedObjects) { + sleep(2); // Check the status (while ignoring existing objects) // if (empty($sExistingIds)) @@ -2360,7 +2361,7 @@ class TestDataExchange extends TestBizModel ), array( array('obj_C', 2, 'obj_C', 'production'), - ), + ), ), 'target_data' => array( array('org_id', 'name', 'status'), @@ -2402,7 +2403,7 @@ class TestDataExchange extends TestBizModel array(2, 'obj_B', 'implementation'), array(2, 'obj_C', 'production'), array(2, 'obj_D', 'obsolete'), - ), + ), ), 'attributes' => array( 'org_id' => array(