浏览代码

#540 Data synchro: the option "write if empty" was not implemented

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1934 a333f486-631f-4898-b8df-5754b55c2be0
romainq 13 年之前
父节点
当前提交
21fb95c5d9
共有 1 个文件被更改,包括 15 次插入2 次删除
  1. 15 2
      synchro/synchrodatasource.class.inc.php

+ 15 - 2
synchro/synchrodatasource.class.inc.php

@@ -1739,8 +1739,21 @@ class SynchroReplica extends DBObject implements iDisplay
 				$value = $this->GetValueFromExtData($sAttCode, $oSyncAtt, $oStatLog);
 				if (!is_null($value))
 				{
-					$oDestObj->Set($sAttCode, $value);
-					$aValueTrace[] = "$sAttCode: $value";
+					if ($oSyncAtt->Get('update_policy') == 'write_if_empty')
+					{
+						$oAttDef = MetaModel::GetAttributeDef(get_class($oDestObj), $sAttCode);
+						if ($oAttDef->IsNull($oDestObj->Get($sAttCode)))
+						{
+							// The value is still "empty" in the target object, we are allowed to write the new value
+							$oDestObj->Set($sAttCode, $value);
+							$aValueTrace[] = "$sAttCode: $value";
+						}
+					}
+					else
+					{
+						$oDestObj->Set($sAttCode, $value);
+						$aValueTrace[] = "$sAttCode: $value";
+					}
 				}
 			}
 			// Really modified ?