rename cron scripts

This commit is contained in:
odain
2026-03-02 10:06:33 +01:00
parent 6f79e1842c
commit 14d748aa97
3 changed files with 26 additions and 20 deletions

View File

@@ -106,7 +106,7 @@ class CronTest extends ItopDataTestCase
'cron_log_file' => $sLogFileName,
];
$sJSONResult = $this->CallItopUri("/webservices/launch_cron_asynchronously.php", $aPostFields);
$sJSONResult = $this->CallItopUri("/webservices/asynchronously_cron.php", $aPostFields);
$this->assertEquals($this->GetExpectedCronResponse(), $sJSONResult);
$sLogFile = $this->CheckLogFileIsGeneratedAndGetFullPath($sLogFileName);
@@ -131,7 +131,7 @@ class CronTest extends ItopDataTestCase
CURLOPT_HTTPHEADER => ["Authorization: Basic $sToken"],
];
$sJSONResult = $this->CallItopUri("/webservices/launch_cron_asynchronously.php", $aPostFields, $aCurlOptions);
$sJSONResult = $this->CallItopUri("/webservices/asynchronously_cron.php", $aPostFields, $aCurlOptions);
$this->assertEquals($this->GetExpectedCronResponse(), $sJSONResult);
$sLogFile = $this->CheckLogFileIsGeneratedAndGetFullPath($sLogFileName);
@@ -156,12 +156,11 @@ class CronTest extends ItopDataTestCase
'auth_pwd' => static::$sPassword,
];
$sJSONResult = $this->CallItopUri("/webservices/launch_cron_asynchronously.php?".http_build_query($aGetFields), $aPostFields);
$sJSONResult = $this->CallItopUri("/webservices/asynchronously_cron.php?".http_build_query($aGetFields), $aPostFields);
$this->assertEquals($this->GetExpectedCronResponse(), $sJSONResult);
$sLogFile = $this->CheckLogFileIsGeneratedAndGetFullPath($sLogFileName);
$this->CheckAdminAccessIssueWithCron($sLogFile);
;
}
public function ModeProvider()

View File

@@ -27,19 +27,29 @@ function IsErrorLine(string $sLine): bool
}
function ReadParam($sParam, $sDefaultValue = null, $sSanitizationFilter = utils::ENUM_SANITIZATION_FILTER_RAW_DATA)
{
$sValue = utils::ReadParam($sParam, null, true, $sSanitizationFilter);
if (is_null($sValue)) {
$sValue = utils::ReadPostedParam($sParam, $sDefaultValue, $sSanitizationFilter);
}
return trim($sValue);
}
function IsCronStartingLine(string $sLine): bool
{
return preg_match('/^Starting: /', $sLine);
}
$oCtx = new ContextTag(ContextTag::TAG_CRON);
\IssueLog::Enable(APPROOT.'log/error.log');
try {
$oCtx = new ContextTag(ContextTag::TAG_CRON);
\IssueLog::Enable(APPROOT.'log/error.log');
LoginWebPage::ResetSession();
$iRet = LoginWebPage::DoLogin(false, false, LoginWebPage::EXIT_RETURN);
if ($iRet != LoginWebPage::EXIT_CODE_OK) {
throw new Exception("Unknown authentication error (retCode=$iRet)", RestResult::UNAUTHORIZED);
throw new \Exception("Unknown authentication error (retCode=$iRet)", RestResult::UNAUTHORIZED);
}
$sCurrentLoginMode = \Combodo\iTop\Application\Helper\Session::Get('login_mode', '');
@@ -75,10 +85,17 @@ try {
$aCronValues[] = "--auth_info=".escapeshellarg($sTokenInfo);
$sCli = GetCliCommand($sPHPExec, $sLogFile, $aCronValues);
$process = popen($sCli, 'r');
if (false === $process){
// $process = proc_open($sCli, 'r');
if (false === $process) {
throw new \Exception("CLI execution issue");
}
/*$aStatus = proc_get_status($process);
if ($aStatus['running']) {
var_dump($aStatus);
throw new \Exception(var_export($aStatus));
}*/
while ($aLines = utils::ReadTail($sLogFile)) {
$sLastLine = array_shift($aLines);
if (IsErrorLine($sLastLine) || IsCronStartingLine($sLastLine)) {
@@ -94,7 +111,7 @@ try {
$oP->SetData(["message" => "OK"]);
$oP->SetOutputDataOnly(true);
$oP->Output();
} catch (Exception $e) {
} catch (\Exception $e) {
\IssueLog::Error('Cannot run cron', null, ['msg' => $e->getMessage(), 'stack' => $e->getTraceAsString()]);
http_response_code(500);
@@ -104,13 +121,3 @@ try {
$oP->SetOutputDataOnly(true);
$oP->Output();
}
function ReadParam($sParam, $sDefaultValue = null, $sSanitizationFilter = utils::ENUM_SANITIZATION_FILTER_RAW_DATA)
{
$sValue = utils::ReadParam($sParam, null, true, $sSanitizationFilter);
if (is_null($sValue)) {
$sValue = utils::ReadPostedParam($sParam, $sDefaultValue, $sSanitizationFilter);
}
return trim($sValue);
}