소스 검색

N°583 CSV Import now supports friendlynames as reconciliation keys. More over, read-only attributes (friendlyname, obsolescence flag, ...) are forced to reconciliation scheme.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4861 a333f486-631f-4898-b8df-5754b55c2be0
glajarige 7 년 전
부모
커밋
16f5567fb8
3개의 변경된 파일29개의 추가작업 그리고 3개의 파일을 삭제
  1. 2 0
      core/bulkchange.class.inc.php
  2. 20 3
      pages/ajax.csvimport.php
  3. 7 0
      pages/csvimport.php

+ 2 - 0
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();

+ 20 - 3
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(
 <<<EOF
 		$('select[name^=field]').change( DoCheckMapping );
 		aDefaultKeys = new Array($sDefaultKeys);
+		aReadOnlyKeys = new Array($sReadOnlyKeys);
 		DoCheckMapping();
 EOF
 );	

+ 7 - 0
pages/csvimport.php

@@ -835,6 +835,7 @@ EOF
 		$oPage->add_script(
 <<<EOF
 	var aDefaultKeys = new Array();
+	var aReadOnlyKeys = new Array();
 	
 	function CSVGoBack()
 	{
@@ -1005,6 +1006,12 @@ EOF
 				$('#search_'+index).attr('checked', false);
 				$('#search_'+index).attr('disabled', true);
 			}
+			else if (aReadOnlyKeys.indexOf(sMappingValue) >= 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