Browse Source

Fixed bug #231: distinguish between external key (id) and external key (name) for loading fields that are external keys pointing to externla keys! Example: Connected To->Device is to be mapped to the Connected Interface's device NAME whereas Connected To->Device->id is to be mapped to the connected interface's device id

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@747 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 15 năm trước cách đây
mục cha
commit
0f3c4491b9
2 tập tin đã thay đổi với 25 bổ sung6 xóa
  1. 8 1
      application/cmdbabstract.class.inc.php
  2. 17 5
      pages/ajax.csvimport.php

+ 8 - 1
application/cmdbabstract.class.inc.php

@@ -661,7 +661,14 @@ abstract class cmdbAbstractObject extends CMDBObject
 				{
 					$sExtKeyLabel = MetaModel::GetLabel($sClassName, $oAttDef->GetKeyAttCode());
 					$sRemoteAttLabel = MetaModel::GetLabel($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
-					$aHeader[] = $sExtKeyLabel.'->'.$sRemoteAttLabel;
+					$oTargetAttDef = MetaModel::GetAttributeDef($oAttDef->GetTargetClass(), $oAttDef->GetExtAttCode());
+					$sSuffix = '';
+					if ($oTargetAttDef->IsExternalKey())
+					{
+						$sSuffix = '->id';
+					}
+					
+					$aHeader[] = $sExtKeyLabel.'->'.$sRemoteAttLabel.$sSuffix;
 				}
 				else
 				{

+ 17 - 5
pages/ajax.csvimport.php

@@ -70,10 +70,16 @@ function GetMappingsForExtKey($sAttCode, AttributeDefinition $oExtKeyAttDef, $bA
 	{
 		if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode))
 		{
-			if ($bAdvanced || !$oTargetAttDef->IsExternalKey())
+			$bExtKey = $oTargetAttDef->IsExternalKey();
+			$sSuffix = '';
+			if ($bExtKey)
+			{
+				$sSuffix = '->id';
+			}
+			if ($bAdvanced || !$bExtKey)
 			{
 				// When not in advanced mode do not allow to use reconciliation keys (on external keys) if they are themselves external keys !
-				$aResult[$sAttCode.'->'.$sTargetAttCode] = $oExtKeyAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel();
+				$aResult[$sAttCode.'->'.$sTargetAttCode] = $oExtKeyAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel().$sSuffix;
 			}
 		}
 	}
@@ -124,12 +130,18 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMo
 			{
 				if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode))
 				{
-					if ($bAdvancedMode || (!$oTargetAttDef->IsExternalKey()))
+					$bExtKey = $oTargetAttDef->IsExternalKey();
+					$sSuffix = '';
+					if ($bExtKey)
+					{
+						$sSuffix = '->id';
+					}
+					if ($bAdvancedMode || !$bExtKey)
 					{
 					
 						// When not in advanced mode do not allow to use reconciliation keys (on external keys) if they are themselves external keys !
-						$aChoices[$sAttCode.'->'.$sTargetAttCode] = $oAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel();
-						if ((strcasecmp($sFieldName, $aChoices[$sAttCode.'->'.$sTargetAttCode]) == 0) || (strcasecmp($sFieldName, ($sAttCode.'->'.$sTargetAttCode)) == 0) )
+						$aChoices[$sAttCode.'->'.$sTargetAttCode] = $oAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel().$sSuffix;
+						if ((strcasecmp($sFieldName, $aChoices[$sAttCode.'->'.$sTargetAttCode]) == 0) || (strcasecmp($sFieldName, ($sAttCode.'->'.$sTargetAttCode.$sSuffix)) == 0) )
 						{
 							$sFieldCode = $sAttCode.'->'.$sTargetAttCode;
 						}