From 3f968a0c2bc6bde8b1632e0f94e4e8d9ec4628c9 Mon Sep 17 00:00:00 2001 From: Anne-Cath Date: Mon, 5 Feb 2024 15:32:03 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B07216=20-=20Import=20:=20bug=20when=20las?= =?UTF-8?q?t=20field=20as=20ExtFieldAttribute=20is=20null=20in=20csv=20fil?= =?UTF-8?q?e=20or=20missing=20a=20comma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/bulkchange.class.inc.php | 24 +++++++++++++++++++++--- pages/ajax.csvimport.php | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/bulkchange.class.inc.php b/core/bulkchange.class.inc.php index ee60143248..78ff6a78d5 100644 --- a/core/bulkchange.class.inc.php +++ b/core/bulkchange.class.inc.php @@ -519,7 +519,7 @@ protected function IsNullExternalKeySpec($aRowData, $sAttCode) foreach ($this->m_aExtKeys[$sAttCode] as $sForeignAttCode => $iCol) { // The foreign attribute is one of our reconciliation key - if (strlen($aRowData[$iCol]) > 0) + if (isset($aRowData[$iCol]) && strlen($aRowData[$iCol]) > 0) { return false; } @@ -1233,11 +1233,19 @@ public function Process(CMDBChange $oChange = null) $iPreviousTimeLimit = ini_get('max_execution_time'); $iLoopTimeLimit = MetaModel::GetConfig()->Get('max_execution_time_per_loop'); + $iNBFields = count($this->m_aAttList) + count($this->m_aExtKeys); + // Avoid too many events cmdbAbstractObject::SetEventDBLinksChangedBlocked(true); try { foreach ($this->m_aData as $iRow => $aRowData) { set_time_limit(intval($iLoopTimeLimit)); + //stop if not enough cols in $aRowData + if(count($aRowData) != $iNBFields){ + $aResult[$iRow]["__STATUS__"] = new RowStatus_Issue('not enough col at line '.$iRow ); + continue; + } + if (isset($aResult[$iRow]["__STATUS__"])) { // An issue at the earlier steps - skip the rest continue; @@ -1348,7 +1356,12 @@ public function Process(CMDBChange $oChange = null) { if (!array_key_exists($iCol, $aResult[$iRow])) { - $aResult[$iRow][$iCol] = new CellStatus_Void($aRowData[$iCol]); + if(isset($aRowData[$iCol])) { + $aResult[$iRow][$iCol] = new CellStatus_Void($aRowData[$iCol]); + } else { + //TODO improve message + $aResult[$iRow][$iCol] = new CellStatus_Void('!missing value!'); + } } } foreach($this->m_aExtKeys as $sAttCode => $aForeignAtts) @@ -1362,7 +1375,12 @@ public function Process(CMDBChange $oChange = null) if (!array_key_exists($iCol, $aResult[$iRow])) { // The foreign attribute is one of our reconciliation key - $aResult[$iRow][$iCol] = new CellStatus_Void($aRowData[$iCol]); + if(isset($aRowData[$iCol])) { + $aResult[$iRow][$iCol] = new CellStatus_Void($aRowData[$iCol]); + } else { + //TODO improve message + $aResult[$iRow][$iCol] = new CellStatus_Void('!missing value!'); + } } } } diff --git a/pages/ajax.csvimport.php b/pages/ajax.csvimport.php index f8f23bde06..adb0d449ed 100644 --- a/pages/ajax.csvimport.php +++ b/pages/ajax.csvimport.php @@ -345,7 +345,7 @@ function GetMappingForField($sClassName, $sFieldName, $iFieldIndex, $bAdvancedMo $oPanel->AddSubBlock($oTable); $oPage->AddSubBlock($oPanel); - if (empty($sInitSearchField)) { + if (empty($sInitSearchField) || empty($aInitFieldMapping)) { // Propose a reconciliation scheme // $aReconciliationKeys = MetaModel::GetReconcKeys($sClassName);