Explorar o código

- Sepcial corner case when loading objects with external keys and these externla keys themsleves have reconciliation keys that are also externla keys.
Example: On a person the field location_id
Can be specified by Location->Name and Location->Owner Organization (The 2 reconciliation keys for the class Location). The latter is also an external key, and therefore only an Id can be supplied for this field. Note that Location->Owner Organization->Name is not yet supported.

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

dflaven %!s(int64=14) %!d(string=hai) anos
pai
achega
b8ebb30055
Modificáronse 2 ficheiros con 18 adicións e 6 borrados
  1. 1 0
      core/bulkchange.class.inc.php
  2. 17 6
      pages/ajax.csvimport.php

+ 1 - 0
core/bulkchange.class.inc.php

@@ -274,6 +274,7 @@ class BulkChange
 				if ($oExtKey->IsNullAllowed())
 				{
 					$oTargetObj->Set($sAttCode, $oExtKey->GetNullValue());
+					$aResults[$sAttCode]= new CellStatus_Issue(null, $oTargetObj->Get($sAttCode), 'Object not found');
 				}
 				else
 				{

+ 17 - 6
pages/ajax.csvimport.php

@@ -58,9 +58,11 @@ function IsIdField($sClassName, $sFieldCode)
 /**
  * Get all the fields xxx->yyy based on the field xxx which is an external key
  * @param string $sExtKeyAttCode Attribute code of the external key
+ * @param AttributeDefinition $oExtKeyAttDef Attribute definition of the external key
+ * @param bool $bAdvanced True if advanced mode
  * @return Ash List of codes=>display name: xxx->yyy where yyy are the reconciliation keys for the object xxx 
  */
-function GetMappingsForExtKey($sAttCode, AttributeDefinition $oExtKeyAttDef)
+function GetMappingsForExtKey($sAttCode, AttributeDefinition $oExtKeyAttDef, $bAdvanced)
 {
 	$aResult = array();
 	$sTargetClass = $oExtKeyAttDef->GetTargetClass();
@@ -68,7 +70,11 @@ function GetMappingsForExtKey($sAttCode, AttributeDefinition $oExtKeyAttDef)
 	{
 		if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode))
 		{
-			$aResult[$sAttCode.'->'.$sTargetAttCode] = $oExtKeyAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel();
+			if ($bAdvanced || !$oTargetAttDef->IsExternalKey())
+			{
+				// 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();
+			}
 		}
 	}
 	return $aResult;	
@@ -118,10 +124,15 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMo
 			{
 				if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode))
 				{
-					$aChoices[$sAttCode.'->'.$sTargetAttCode] = $oAttDef->GetLabel().'->'.$oTargetAttDef->GetLabel();
-					if ((strcasecmp($sFieldName, $aChoices[$sAttCode.'->'.$sTargetAttCode]) == 0) || (strcasecmp($sFieldName, ($sAttCode.'->'.$sTargetAttCode)) == 0) )
+					if ($bAdvancedMode || (!$oTargetAttDef->IsExternalKey()))
 					{
-						$sFieldCode = $sAttCode.'->'.$sTargetAttCode;
+					
+						// 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) )
+						{
+							$sFieldCode = $sAttCode.'->'.$sTargetAttCode;
+						}
 					}
 				}
 			}
@@ -303,7 +314,7 @@ switch($sOperation)
 			$oAttDef = MetaModel::GetAttributeDef($sClassName, $sAttCode);
 			if ($oAttDef->IsExternalKey())
 			{
-				$aMoreReconciliationKeys = array_keys(GetMappingsForExtKey($sAttCode, $oAttDef));
+				$aMoreReconciliationKeys = array_keys(GetMappingsForExtKey($sAttCode, $oAttDef, $bAdvanced));
 			}
 		}
 		$sDefaultKeys = '"'.implode('", "',array_merge($aReconciliationKeys,$aMoreReconciliationKeys)).'"';