From 0d710d046412a4c382c69bb4ad99a9a33bfb93b4 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Thu, 28 Apr 2011 14:02:01 +0000 Subject: [PATCH] #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 SVN:trunk[1248] --- test/test.php | 2 +- test/testlist.inc.php | 4 ++-- webservices/import.php | 20 ++++++++++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/test/test.php b/test/test.php index 526325437..2e9458d6c 100644 --- a/test/test.php +++ b/test/test.php @@ -30,7 +30,7 @@ font-size:8pt; line-height:100%; } - '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', ), diff --git a/webservices/import.php b/webservices/import.php index 6fd764b94..924f1176b 100644 --- a/webservices/import.php +++ b/webservices/import.php @@ -344,7 +344,13 @@ try ////////////////////////////////////////////////// // - // Make translated header reference + // Make translated column reference + // + // array of => + // + // 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))