瀏覽代碼

- Don't create warnings for empty ext keys (i.e. empty string)
- Properly record multiple warnings
- Don't record warnings in case of creation error (error has precedence)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1688 a333f486-631f-4898-b8df-5754b55c2be0

dflaven 13 年之前
父節點
當前提交
2b9185922e
共有 1 個文件被更改,包括 33 次插入10 次删除
  1. 33 10
      synchro/synchrodatasource.class.inc.php

+ 33 - 10
synchro/synchrodatasource.class.inc.php

@@ -1737,7 +1737,7 @@ class SynchroReplica extends DBObject implements iDisplay
 			break;
 			
 			default:
-			$sWarningMessage = count($this->aWarnings)." warnings: ".implode(' '.$this->aWarnings);
+			$sWarningMessage = count($this->aWarnings)." warnings: ".implode(' ', $this->aWarnings);
 			break;
 		}
 
@@ -1845,10 +1845,18 @@ class SynchroReplica extends DBObject implements iDisplay
 				$oStatLog->AddTrace("Nothing found on: $sConditionDesc", $this);
 				if ($oDataSource->Get('action_on_zero') == 'create')
 				{
-					$this->CreateObjectFromReplica($oDataSource->GetTargetClass(), $aAttributes, $oChange, $oStatLog);
-					if ($this->HasWarnings())
+					$bCreated = $this->CreateObjectFromReplica($oDataSource->GetTargetClass(), $aAttributes, $oChange, $oStatLog);
+					if ($bCreated)
 					{
-						$oStatLog->Inc('stats_nb_obj_created_warnings');
+						if ($this->HasWarnings())
+						{
+							$oStatLog->Inc('stats_nb_obj_created_warnings');
+						}
+					}
+					else
+					{
+						// Creation error has precedence over any warning
+						$this->ResetWarnings();
 					}
 				}
 				else // assumed to be 'error'
@@ -1901,10 +1909,18 @@ class SynchroReplica extends DBObject implements iDisplay
 				}
 				elseif ($oDataSource->Get('action_on_multiple') == 'create')
 				{
-					$this->CreateObjectFromReplica($oDataSource->GetTargetClass(), $aAttributes, $oChange, $oStatLog);
-					if ($this->HasWarnings())
+					$bCreated = $this->CreateObjectFromReplica($oDataSource->GetTargetClass(), $aAttributes, $oChange, $oStatLog);
+					if ($bCreated)
 					{
-						$oStatLog->Inc('stats_nb_obj_created_warnings');
+						if ($this->HasWarnings())
+						{
+							$oStatLog->Inc('stats_nb_obj_created_warnings');
+						}
+					}
+					else
+					{
+						// Creation error has precedence over any warning
+						$this->ResetWarnings();
 					}
 				}
 				else
@@ -2014,9 +2030,11 @@ class SynchroReplica extends DBObject implements iDisplay
 
 	/**
 	 * Creates the destination object populating it with the Extended data found in the synchro_data_XXXX table
+	 * @return bool Whether or not the object was created
 	 */	
 	protected function CreateObjectFromReplica($sClass, $aAttributes, $oChange, &$oStatLog)
 	{
+		$bCreated = false;
 		$oDestObj = MetaModel::NewObject($sClass);
 		try
 		{
@@ -2038,6 +2056,7 @@ class SynchroReplica extends DBObject implements iDisplay
 			$this->Set('status_last_error', '');
 			$this->Set('status', 'synchronized');
 			$this->Set('info_creation_date', date('Y-m-d H:i:s'));
+			$bCreated = true;
 
 			$oStatLog->AddTrace("Created (".implode(', ', $aValueTrace).")", $this);
 			$oStatLog->Inc('stats_nb_obj_created');
@@ -2048,6 +2067,7 @@ class SynchroReplica extends DBObject implements iDisplay
 			$this->SetLastError('Unable to create destination object: ', $e);
 			$oStatLog->Inc('stats_nb_obj_created_errors');
 		}
+		return $bCreated;
 	}
 	
 	/**
@@ -2165,9 +2185,12 @@ class SynchroReplica extends DBObject implements iDisplay
 				}
 				else
 				{
-					// Note: differs from null (in which case the value would be left unchanged)
-					$oStatLog->AddTrace("Could not find [unique] object for '$sExtAttCode': searched on $sReconcAttCode = '$rawValue'", $this);
-					$this->AddWarning("Could not find [unique] object for '$sExtAttCode': searched on $sReconcAttCode = '$rawValue'");
+					if ($rawValue != '')
+					{
+						// Note: differs from null (in which case the value would be left unchanged)
+						$oStatLog->AddTrace("Could not find [unique] object for '$sExtAttCode': searched on $sReconcAttCode = '$rawValue'", $this);
+						$this->AddWarning("Could not find [unique] object for '$sExtAttCode': searched on $sReconcAttCode = '$rawValue'");
+					}
 					$retValue = 0;
 				}
 			}