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()
{
$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;

View File

@@ -211,13 +211,15 @@ 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");
}
try
{
utils::UseParamFile();
@@ -231,9 +233,13 @@ catch(Exception $e)
if (utils::IsModeCLI())
{
$sCleanName = strtolower(trim(PHP_SAPI));
$bIsCli = ($sCleanName === 'cli');
$oP->p("mode CLI bIsCli: $bIsCli sCleanName: $sCleanName");
// 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');
@@ -259,6 +265,10 @@ if (utils::IsModeCLI())
}
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');
LoginWebPage::ResetSession(true);
$iRet = LoginWebPage::DoLogin(false, false, LoginWebPage::EXIT_RETURN);
@@ -303,7 +313,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 +366,7 @@ try
{
$sDateFormat = null;
}
if ($sCharSet == '')
{
$sCharSet = MetaModel::GetConfig()->Get('csv_file_default_charset');
@@ -474,7 +484,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 +506,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 +528,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 +763,7 @@ try
}
CMDBObject::SetTrackInfo($sMoreInfo);
CMDBObject::SetTrackOrigin('csv-import.php');
$oMyChange = CMDBObject::GetCurrentChange();
}
@@ -788,7 +798,7 @@ try
break;
case 'RowStatus_Issue':
$iCountErrors++;
break;
break;
}
if ($bWritten)
@@ -867,7 +877,7 @@ try
$aDisplayConfig["$iCol"] = array("label"=>$sAttCode, "description"=>$sLabel);
}
}
$aResultDisp = array(); // to be displayed
foreach($aRes as $iRow => $aRowData)
{
@@ -894,11 +904,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 +925,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();