#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]
This commit is contained in:
Romain Quetiez
2011-04-28 14:02:01 +00:00
parent 40701f3f36
commit 0d710d0464
3 changed files with 21 additions and 5 deletions

View File

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

View File

@@ -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',
),

View File

@@ -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))