فهرست منبع

#355 (continuation of the fix) import.php to support localized names in the specification of reconciliation keys, and allowing to specify an external key though it is given as an external field in the input columns

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1248 a333f486-631f-4898-b8df-5754b55c2be0
romainq 14 سال پیش
والد
کامیت
bcfc41fd29
3فایلهای تغییر یافته به همراه21 افزوده شده و 5 حذف شده
  1. 1 1
      test/test.php
  2. 2 2
      test/testlist.inc.php
  3. 18 2
      webservices/import.php

+ 1 - 1
test/test.php

@@ -30,7 +30,7 @@ font-size:8pt;
 line-height:100%;
 }
 </style>
-<?
+<?php
 
 ///////////////////////////////////////////////////////////////////////////////
 // Helpers

+ 2 - 2
test/testlist.inc.php

@@ -1638,9 +1638,9 @@ class TestImportREST extends TestWebServices
 					'class' => 'NetworkDevice',
 					'output' => 'details',
 					'separator' => ';',
-					'reconciliationkeys' => 'org_id->name,name',
+					'reconciliationkeys' => 'org_id,Name',
 					),
-				'csvdata' => 'name;management_ip;importance;org_id->name;type
+				'csvdata' => 'name;management_ip;importance;Owner organization->Name;type
 									truc-machin-bidule;172.15.255.150;high;My Company/Department;switch
 									10.15.255.222;10.15.255.222;high;My Company/Department;switch',
 			),

+ 18 - 2
webservices/import.php

@@ -344,7 +344,13 @@ try
 
 	//////////////////////////////////////////////////
 	//
-	// Make translated header reference
+	// Make translated column reference
+	//
+	// array of <LowercaseTranslatedName> => <ExtendedAttCode>
+	//
+	// Examples:
+	//   'organization' => 'org_id'
+	//   'organization->name' => 'org_id->name'
 	//
 	$aFriendlyToInternalAttCode = array();
 	foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
@@ -487,9 +493,19 @@ try
 		$sReconcKey = trim($sReconcKey);
 		if (empty($sReconcKey)) continue; // skip empty spec
 
+		if (array_key_exists(strtolower($sReconcKey), $aFriendlyToInternalAttCode))
+		{
+			// Translate from a translated name to codes
+			$sReconcKey = $aFriendlyToInternalAttCode[strtolower($sReconcKey)];
+		}
+
+		// Check that the reconciliation key is either a given column, or an external key
 		if (!in_array($sReconcKey, $aFieldList))
 		{
-			throw new BulkLoadException("Reconciliation keys not found in the input columns '$sReconcKey' (class: '$sClass')");
+			if (!array_key_exists($sReconcKey, $aExtKeys))
+			{
+				throw new BulkLoadException("Reconciliation keys not found in the input columns '$sReconcKey' (class: '$sClass')");
+			}
 		}
 
 		if (preg_match('/^(.+)->(.+)$/', trim($sReconcKey), $aMatches))