Explorar o código

CSV import: regression due to a recent enhancement (labels) and the fact that some labels are redundant (e.g. "Location" used both for Server/location_id and Server/location_name

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1254 a333f486-631f-4898-b8df-5754b55c2be0
romainq %!s(int64=14) %!d(string=hai) anos
pai
achega
657c8ba311
Modificáronse 1 ficheiros con 14 adicións e 3 borrados
  1. 14 3
      webservices/import.php

+ 14 - 3
webservices/import.php

@@ -352,17 +352,28 @@ try
 	//   'organization' => 'org_id'
 	//   'organization->name' => 'org_id->name'
 	//
+	// Note: it may happen that an external field has the same label as the external key
+	//       in that case, we consider that the external key has precedence
+	//
 	$aFriendlyToInternalAttCode = array();
 	foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
 	{
-	  	$aFriendlyToInternalAttCode[strtolower(BulkChange::GetFriendlyAttCodeName($sClass, $sAttCode))] = $sAttCode;
+	  	$sFriendlyName = strtolower(BulkChange::GetFriendlyAttCodeName($sClass, $sAttCode));
+	  	if (!$oAttDef->IsExternalField() || !array_key_exists($sFriendlyName, $aFriendlyToInternalAttCode))
+	  	{
+		  	$aFriendlyToInternalAttCode[$sFriendlyName] = $sAttCode;
+		}
 	  	if ($oAttDef->IsExternalKey(EXTKEY_RELATIVE))
 	  	{
 	  		$sRemoteClass = $oAttDef->GetTargetClass();
 			foreach(MetaModel::ListAttributeDefs($sRemoteClass) as $sRemoteAttCode => $oRemoteAttDef)
 		  	{
-		  		$sAttCodeEx = $sAttCode.'->'.$sRemoteAttCode;
-		  		$aFriendlyToInternalAttCode[strtolower(BulkChange::GetFriendlyAttCodeName($sClass, $sAttCodeEx))] = $sAttCodeEx;
+	  			$sAttCodeEx = $sAttCode.'->'.$sRemoteAttCode;
+	  			$sFriendlyName = strtolower(BulkChange::GetFriendlyAttCodeName($sClass, $sAttCodeEx));
+		  		if (!array_key_exists($sFriendlyName, $aFriendlyToInternalAttCode))
+		  		{
+		  			$aFriendlyToInternalAttCode[$sFriendlyName] = $sAttCodeEx;
+		  		}
 		  	}
 		}
    }