From 4171c5c35fa176df5b5421f66f7dca66e8c73053 Mon Sep 17 00:00:00 2001 From: Guillaume Lajarige Date: Thu, 17 Aug 2017 09:51:38 +0000 Subject: [PATCH] =?UTF-8?q?N=C2=B0583=20CSV=20Import=20now=20supports=20fr?= =?UTF-8?q?iendlynames=20as=20reconciliation=20keys.=20More=20over,=20read?= =?UTF-8?q?-only=20attributes=20(friendlyname,=20obsolescence=20flag,=20..?= =?UTF-8?q?.)=20are=20forced=20to=20reconciliation=20scheme.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SVN:trunk[4861] --- core/bulkchange.class.inc.php | 2 ++ pages/ajax.csvimport.php | 23 ++++++++++++++++++++--- pages/csvimport.php | 7 +++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/core/bulkchange.class.inc.php b/core/bulkchange.class.inc.php index 75a0d05b1..5658c96aa 100644 --- a/core/bulkchange.class.inc.php +++ b/core/bulkchange.class.inc.php @@ -470,6 +470,8 @@ class BulkChange { // skip the private key, if any if ($sAttCode == 'id') continue; + // skip reconciliation keys + if (in_array($sAttCode, $this->m_aReconcilKeys)) continue; $oAttDef = MetaModel::GetAttributeDef($this->m_sClass, $sAttCode); $aReasons = array(); diff --git a/pages/ajax.csvimport.php b/pages/ajax.csvimport.php index f3333604e..df95b721f 100644 --- a/pages/ajax.csvimport.php +++ b/pages/ajax.csvimport.php @@ -149,7 +149,8 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMo $sTargetClass = $oAttDef->GetTargetClass(); foreach(MetaModel::ListAttributeDefs($sTargetClass) as $sTargetAttCode => $oTargetAttDef) { - if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode)) + // Note: Could not use "MetaModel::GetFriendlyNameAttributeCode($sTargetClass) === $sTargetAttCode" as it would return empty because the friendlyname is composite. + if (MetaModel::IsReconcKey($sTargetClass, $sTargetAttCode) || ($oTargetAttDef instanceof AttributeFriendlyName)) { $bExtKey = $oTargetAttDef->IsExternalKey(); $aSignatures = array(); @@ -176,14 +177,17 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMo } } } - else if ($oAttDef->IsWritable() && (!$oAttDef->IsLinkset() || ($bAdvancedMode && $oAttDef->IsIndirect()))) + else if ( + ($oAttDef->IsWritable() && (!$oAttDef->IsLinkset() || ($bAdvancedMode && $oAttDef->IsIndirect()))) + || ($oAttDef instanceof AttributeFriendlyName) + ) { $aChoices[$sAttCode] = MetaModel::GetLabel($sClassName, $sAttCode, true); if ( ($sFieldName == $oAttDef->GetLabel()) || ($sFieldName == $sAttCode)) { $sFieldCode = $sAttCode; } - } + } } asort($aChoices); @@ -412,10 +416,23 @@ try } $sDefaultKeys = '"'.implode('", "', $aDefaultKeys).'"'; } + + // Read only attributes (will be forced to "search") + $aReadOnlyKeys = array(); + foreach(MetaModel::ListAttributeDefs($sClassName) as $sAttCode => $oAttDef) + { + if(!$oAttDef->IsWritable()) + { + $aReadOnlyKeys[] = $sAttCode; + } + } + $sReadOnlyKeys = '"'.implode('", "', $aReadOnlyKeys).'"'; + $oPage->add_ready_script( <<add_script( <<= 0) + { + // Read-only attribute forced to reconciliation key + $('#search_'+index).attr('checked', true); + $('#search_'+index).attr('disabled', true); + } else if (index == idSelected) { // The 'id' field was mapped, it's the only possible reconciliation key