Pārlūkot izejas kodu

Data sync: fixed issue when a replica left in state 'new' becomes obsolete

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1668 a333f486-631f-4898-b8df-5754b55c2be0
romainq 13 gadi atpakaļ
vecāks
revīzija
4e1e2d45ba

+ 9 - 1
synchro/synchro_import.php

@@ -223,6 +223,14 @@ function ChangeDateFormat($sProposedDate, $sDateFormat)
 }
 
 
+class CLILikeWebPage extends WebPage
+{
+	public function add_comment($sText)
+	{
+		$this->add('#'.$sText."<br/>\n");
+	}
+}
+
 /////////////////////////////////
 // Main program
 
@@ -232,7 +240,7 @@ if (utils::IsModeCLI())
 }
 else
 {
-	$oP = new WebPage(Dict::S("TitleSynchroExecution"));
+	$oP = new CLILikeWebPage(Dict::S("TitleSynchroExecution"));
 }
 
 try

+ 16 - 5
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');
 				}

+ 3 - 2
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(