mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
N°2214 Add PHP check in CLI scripts
It is quite common that the PHP interpreter that is launched in CLI is different that the one used by the webserver. So iTop code launched by CLI could run in a context that doesn't meet iTop requirements !
This adds in the following scripts the same control that is done on the setup wizard first step :
* cron.php
* backup, check-backup
* export, exportv2
* bulk import
* synchro-exec, synchro-import
If the check throws at least one error then the script is stopped with an appropriate message, and a log is made (IssueLog, Error level, CLI channel)
(cherry picked from commit c768e18e2b : no risk taken for 2.7.1, so cherry picked for 2.8.0)
This commit is contained in:
@@ -32,6 +32,12 @@ require_once(APPROOT.'/core/bulkexport.class.inc.php');
|
||||
require_once(APPROOT.'/application/startup.inc.php');
|
||||
|
||||
|
||||
|
||||
const EXIT_CODE_ERROR = -1;
|
||||
const EXIT_CODE_FATAL = -2;
|
||||
|
||||
|
||||
|
||||
function ReportErrorAndExit($sErrorMessage)
|
||||
{
|
||||
if (utils::IsModeCLI())
|
||||
@@ -39,14 +45,14 @@ function ReportErrorAndExit($sErrorMessage)
|
||||
$oP = new CLIPage("iTop - Export");
|
||||
$oP->p('ERROR: '.$sErrorMessage);
|
||||
$oP->output();
|
||||
exit(-1);
|
||||
exit(EXIT_CODE_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oP = new WebPage("iTop - Export");
|
||||
$oP->p('ERROR: '.$sErrorMessage);
|
||||
$oP->output();
|
||||
exit(-1);
|
||||
exit(EXIT_CODE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +64,7 @@ function ReportErrorAndUsage($sErrorMessage)
|
||||
$oP->p('ERROR: '.$sErrorMessage);
|
||||
Usage($oP);
|
||||
$oP->output();
|
||||
exit(-1);
|
||||
exit(EXIT_CODE_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -66,7 +72,7 @@ function ReportErrorAndUsage($sErrorMessage)
|
||||
$oP->p('ERROR: '.$sErrorMessage);
|
||||
Usage($oP);
|
||||
$oP->output();
|
||||
exit(-1);
|
||||
exit(EXIT_CODE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -565,6 +571,8 @@ function DoExport(WebPage $oP, BulkExport $oExporter, $bInteractive = false)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
if (utils::IsModeCLI())
|
||||
{
|
||||
SetupUtils::CheckPhpAndExtensionsForCli(new CLIPage('iTop - Export'));
|
||||
|
||||
try
|
||||
{
|
||||
// Do this before loging, in order to allow setting user credentials from within the file
|
||||
@@ -573,7 +581,7 @@ if (utils::IsModeCLI())
|
||||
catch(Exception $e)
|
||||
{
|
||||
echo "Error: ".$e->GetMessage()."<br/>\n";
|
||||
exit(-2);
|
||||
exit(EXIT_CODE_FATAL);
|
||||
}
|
||||
|
||||
$sAuthUser = utils::ReadParam('auth_user', null, true /* Allow CLI */, 'raw_data');
|
||||
|
||||
Reference in New Issue
Block a user