Compare commits

...

2 Commits

Author SHA1 Message Date
odain
e4ea5ce0e9 add log 2024-05-16 16:41:44 +02:00
odain
ffb0d4c68e add debug info on CliResetSessionTest import 2024-05-16 16:23:14 +02:00
2 changed files with 32 additions and 16 deletions

View File

@@ -200,7 +200,13 @@ class utils
public static function IsModeCLI() public static function IsModeCLI()
{ {
$sCleanName = strtolower(trim(PHP_SAPI)); $sCleanName = strtolower(trim(PHP_SAPI));
return ($sCleanName === 'cli'); $bRes = $sCleanName === 'cli';
IssueLog::Error("IsModeCLI", null, [
'sCleanName' => $sCleanName,
'bRes' => $bRes,
]);
return $bRes;
} }
protected static $bPageMode = null; protected static $bPageMode = null;

View File

@@ -211,13 +211,15 @@ function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter)
if (utils::IsModeCLI()) if (utils::IsModeCLI())
{ {
$oP = new CLIPage("iTop - Bulk import"); $oP = new CLIPage("iTop IsModeCLI - Bulk import");
} }
else else
{ {
$oP = new CSVPage("iTop - Bulk import"); $oP = new CSVPage("iTop - Bulk import");
} }
try try
{ {
utils::UseParamFile(); utils::UseParamFile();
@@ -231,9 +233,13 @@ catch(Exception $e)
if (utils::IsModeCLI()) if (utils::IsModeCLI())
{ {
$sCleanName = strtolower(trim(PHP_SAPI));
$bIsCli = ($sCleanName === 'cli');
$oP->p("mode CLI bIsCli: $bIsCli sCleanName: $sCleanName");
// Next steps: // Next steps:
// specific arguments: 'csvfile' // specific arguments: 'csvfile'
// //
$sAuthUser = ReadMandatoryParam($oP, 'auth_user', 'raw_data'); $sAuthUser = ReadMandatoryParam($oP, 'auth_user', 'raw_data');
$sAuthPwd = ReadMandatoryParam($oP, 'auth_pwd', 'raw_data'); $sAuthPwd = ReadMandatoryParam($oP, 'auth_pwd', 'raw_data');
$sCsvFile = ReadMandatoryParam($oP, 'csvfile', 'raw_data'); $sCsvFile = ReadMandatoryParam($oP, 'csvfile', 'raw_data');
@@ -259,6 +265,10 @@ if (utils::IsModeCLI())
} }
else else
{ {
$sCleanName = strtolower(trim(PHP_SAPI));
$bIsCli = ($sCleanName === 'cli');
$oP->p("mode WEB bIsCli: $bIsCli sCleanName: $sCleanName");
require_once(APPROOT.'/application/loginwebpage.class.inc.php'); require_once(APPROOT.'/application/loginwebpage.class.inc.php');
LoginWebPage::ResetSession(true); LoginWebPage::ResetSession(true);
$iRet = LoginWebPage::DoLogin(false, false, LoginWebPage::EXIT_RETURN); $iRet = LoginWebPage::DoLogin(false, false, LoginWebPage::EXIT_RETURN);
@@ -303,7 +313,7 @@ try
// //
// Read parameters // 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'); $sSep = ReadParam($oP, 'separator', 'raw_data');
$sQualifier = ReadParam($oP, 'qualifier', 'raw_data'); $sQualifier = ReadParam($oP, 'qualifier', 'raw_data');
$sCharSet = ReadParam($oP, 'charset', 'raw_data'); $sCharSet = ReadParam($oP, 'charset', 'raw_data');
@@ -356,7 +366,7 @@ try
{ {
$sDateFormat = null; $sDateFormat = null;
} }
if ($sCharSet == '') if ($sCharSet == '')
{ {
$sCharSet = MetaModel::GetConfig()->Get('csv_file_default_charset'); $sCharSet = MetaModel::GetConfig()->Get('csv_file_default_charset');
@@ -474,7 +484,7 @@ try
{ {
$sUTF8Data = iconv($sCharSet, 'UTF-8//IGNORE//TRANSLIT', $sCSVData); $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 // Limitation: as the attribute list is in the first line, we can not match external key by a third-party attribute
$aRawFieldList = $oCSVParser->ListFields(); $aRawFieldList = $oCSVParser->ListFields();
@@ -496,7 +506,7 @@ try
// Remove any trailing "star" character before the arrow (->) // Remove any trailing "star" character before the arrow (->)
// A star character at the end can be used to indicate a mandatory field // A star character at the end can be used to indicate a mandatory field
$sFieldName = $aMatches[1].'->'.$aMatches[2]; $sFieldName = $aMatches[1].'->'.$aMatches[2];
} }
if (array_key_exists(strtolower($sFieldName), $aKnownColumnNames)) if (array_key_exists(strtolower($sFieldName), $aKnownColumnNames))
{ {
$aColumns = $aKnownColumnNames[strtolower($sFieldName)]; $aColumns = $aKnownColumnNames[strtolower($sFieldName)];
@@ -518,7 +528,7 @@ try
throw new BulkLoadException("Unknown column: '$sSafeName'. Possible columns: ".implode(', ', array_keys($aKnownColumnNames))); 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(); $aAttList = array();
$aExtKeys = array(); $aExtKeys = array();
@@ -753,7 +763,7 @@ try
} }
CMDBObject::SetTrackInfo($sMoreInfo); CMDBObject::SetTrackInfo($sMoreInfo);
CMDBObject::SetTrackOrigin('csv-import.php'); CMDBObject::SetTrackOrigin('csv-import.php');
$oMyChange = CMDBObject::GetCurrentChange(); $oMyChange = CMDBObject::GetCurrentChange();
} }
@@ -788,7 +798,7 @@ try
break; break;
case 'RowStatus_Issue': case 'RowStatus_Issue':
$iCountErrors++; $iCountErrors++;
break; break;
} }
if ($bWritten) if ($bWritten)
@@ -867,7 +877,7 @@ try
$aDisplayConfig["$iCol"] = array("label"=>$sAttCode, "description"=>$sLabel); $aDisplayConfig["$iCol"] = array("label"=>$sAttCode, "description"=>$sLabel);
} }
} }
$aResultDisp = array(); // to be displayed $aResultDisp = array(); // to be displayed
foreach($aRes as $iRow => $aRowData) foreach($aRes as $iRow => $aRowData)
{ {
@@ -894,11 +904,11 @@ try
foreach($aRowData as $key => $value) foreach($aRowData as $key => $value)
{ {
$sKey = (string) $key; $sKey = (string) $key;
if ($sKey == '__STATUS__') continue; if ($sKey == '__STATUS__') continue;
if ($sKey == 'finalclass') continue; if ($sKey == 'finalclass') continue;
if ($sKey == 'id') continue; if ($sKey == 'id') continue;
if (is_object($value)) if (is_object($value))
{ {
$aRowDisp["$sKey"] = $value->GetDisplayableValue().$value->GetDescription(); $aRowDisp["$sKey"] = $value->GetDisplayableValue().$value->GetDescription();
@@ -915,15 +925,15 @@ try
} }
catch(BulkLoadException $e) catch(BulkLoadException $e)
{ {
$oP->add_comment($e->getMessage()); $oP->add_comment($e->getMessage());
} }
catch(SecurityException $e) catch(SecurityException $e)
{ {
$oP->add_comment($e->getMessage()); $oP->add_comment($e->getMessage());
} }
catch(Exception $e) catch(Exception $e)
{ {
$oP->add_comment((string)$e); $oP->add_comment((string)$e);
} }
$oP->output(); $oP->output();