From ffb0d4c68e020f07d08ca06ee87fae137814d558 Mon Sep 17 00:00:00 2001 From: odain Date: Thu, 16 May 2024 16:23:14 +0200 Subject: [PATCH] add debug info on CliResetSessionTest import --- webservices/import.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/webservices/import.php b/webservices/import.php index 59fea608f..1e7bc5d52 100644 --- a/webservices/import.php +++ b/webservices/import.php @@ -211,13 +211,18 @@ function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter) if (utils::IsModeCLI()) { - $oP = new CLIPage("iTop - Bulk import"); + $oP = new CLIPage("iTop IsModeCLI - Bulk import"); } else { $oP = new CSVPage("iTop - Bulk import"); } +$sCleanName = strtolower(trim(PHP_SAPI)); +$bIsCli = ($sCleanName === 'cli'); +$oP->p("bIsCli: $bIsCli sCleanName: $sCleanName"); + + try { utils::UseParamFile(); @@ -233,7 +238,7 @@ if (utils::IsModeCLI()) { // Next steps: // specific arguments: 'csvfile' - // + // $sAuthUser = ReadMandatoryParam($oP, 'auth_user', 'raw_data'); $sAuthPwd = ReadMandatoryParam($oP, 'auth_pwd', 'raw_data'); $sCsvFile = ReadMandatoryParam($oP, 'csvfile', 'raw_data'); @@ -303,7 +308,7 @@ try // // Read parameters // - $sClass = ReadMandatoryParam($oP, 'class', 'raw_data'); // do not filter as a valid class, we want to produce the report "wrong class" ourselves + $sClass = ReadMandatoryParam($oP, 'class', 'raw_data'); // do not filter as a valid class, we want to produce the report "wrong class" ourselves $sSep = ReadParam($oP, 'separator', 'raw_data'); $sQualifier = ReadParam($oP, 'qualifier', 'raw_data'); $sCharSet = ReadParam($oP, 'charset', 'raw_data'); @@ -356,7 +361,7 @@ try { $sDateFormat = null; } - + if ($sCharSet == '') { $sCharSet = MetaModel::GetConfig()->Get('csv_file_default_charset'); @@ -474,7 +479,7 @@ try { $sUTF8Data = iconv($sCharSet, 'UTF-8//IGNORE//TRANSLIT', $sCSVData); } - $oCSVParser = new CSVParser($sUTF8Data, $sSep, $sQualifier); + $oCSVParser = new CSVParser($sUTF8Data, $sSep, $sQualifier); // Limitation: as the attribute list is in the first line, we can not match external key by a third-party attribute $aRawFieldList = $oCSVParser->ListFields(); @@ -496,7 +501,7 @@ try // Remove any trailing "star" character before the arrow (->) // A star character at the end can be used to indicate a mandatory field $sFieldName = $aMatches[1].'->'.$aMatches[2]; - } + } if (array_key_exists(strtolower($sFieldName), $aKnownColumnNames)) { $aColumns = $aKnownColumnNames[strtolower($sFieldName)]; @@ -518,7 +523,7 @@ try throw new BulkLoadException("Unknown column: '$sSafeName'. Possible columns: ".implode(', ', array_keys($aKnownColumnNames))); } } - // Note: at this stage the list of fields is supposed to be made of attcodes (and the symbol '->') + // Note: at this stage the list of fields is supposed to be made of attcodes (and the symbol '->') $aAttList = array(); $aExtKeys = array(); @@ -753,7 +758,7 @@ try } CMDBObject::SetTrackInfo($sMoreInfo); CMDBObject::SetTrackOrigin('csv-import.php'); - + $oMyChange = CMDBObject::GetCurrentChange(); } @@ -788,7 +793,7 @@ try break; case 'RowStatus_Issue': $iCountErrors++; - break; + break; } if ($bWritten) @@ -867,7 +872,7 @@ try $aDisplayConfig["$iCol"] = array("label"=>$sAttCode, "description"=>$sLabel); } } - + $aResultDisp = array(); // to be displayed foreach($aRes as $iRow => $aRowData) { @@ -894,11 +899,11 @@ try foreach($aRowData as $key => $value) { $sKey = (string) $key; - + if ($sKey == '__STATUS__') continue; if ($sKey == 'finalclass') continue; if ($sKey == 'id') continue; - + if (is_object($value)) { $aRowDisp["$sKey"] = $value->GetDisplayableValue().$value->GetDescription(); @@ -915,15 +920,15 @@ try } catch(BulkLoadException $e) { - $oP->add_comment($e->getMessage()); + $oP->add_comment($e->getMessage()); } catch(SecurityException $e) { - $oP->add_comment($e->getMessage()); + $oP->add_comment($e->getMessage()); } catch(Exception $e) { - $oP->add_comment((string)$e); + $oP->add_comment((string)$e); } $oP->output();