mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Revert "N°2214 Add PHP check in CLI scripts"
This reverts commit c768e18e2b.
No risk taken for the 2.7.1 : this will be included but for 2.8 !
This commit is contained in:
@@ -29,13 +29,9 @@ require_once(APPROOT."/application/webpage.class.inc.php");
|
||||
|
||||
class CLIPage implements Page
|
||||
{
|
||||
/** @var string */
|
||||
public $s_title;
|
||||
|
||||
function __construct($s_title)
|
||||
function __construct($s_title)
|
||||
{
|
||||
$this->s_title = $s_title;
|
||||
}
|
||||
}
|
||||
|
||||
public function output()
|
||||
{
|
||||
@@ -52,22 +48,22 @@ class CLIPage implements Page
|
||||
public function add($sText)
|
||||
{
|
||||
echo $sText;
|
||||
}
|
||||
}
|
||||
|
||||
public function p($sText)
|
||||
{
|
||||
echo $sText."\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function pre($sText)
|
||||
{
|
||||
echo $sText."\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function add_comment($sText)
|
||||
{
|
||||
echo "#".$sText."\n";
|
||||
}
|
||||
}
|
||||
|
||||
public function table($aConfig, $aData, $aParams = array())
|
||||
{
|
||||
@@ -97,3 +93,5 @@ class CLIPage implements Page
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -134,8 +134,6 @@ set_time_limit(0);
|
||||
if (utils::IsModeCLI())
|
||||
{
|
||||
$oP = new CLIPage("iTop - Database Backup");
|
||||
|
||||
SetupUtils::CheckPhpAndExtensionsForCli($oP);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -250,8 +250,6 @@ catch(Exception $e)
|
||||
|
||||
if (utils::IsModeCLI())
|
||||
{
|
||||
SetupUtils::CheckPhpAndExtensionsForCli(new CLIPage('Check backup utility'));
|
||||
|
||||
echo date('Y-m-d H:i:s')." - running check-backup utility\n";
|
||||
try
|
||||
{
|
||||
|
||||
@@ -39,49 +39,6 @@ class CheckResult
|
||||
$this->sLabel = $sLabel;
|
||||
$this->sDescription = $sDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @since 2.7.1 2.8.0 N°2214
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$sPrintDesc = (empty($this->sDescription)) ? '' : " ({$this->sDescription})";
|
||||
return "{$this->sLabel}$sPrintDesc";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \CheckResult[] $aResults
|
||||
*
|
||||
* @return \CheckResult[] only elements that are error (iSeverity===ERROR)
|
||||
*
|
||||
* @since 2.7.1 2.8.0 N°2214
|
||||
*/
|
||||
public static function KeepOnlyErrors($aResults)
|
||||
{
|
||||
return array_filter($aResults,
|
||||
static function ($v)
|
||||
{
|
||||
if ($v->iSeverity === CheckResult::ERROR) {
|
||||
return $v;
|
||||
}
|
||||
},
|
||||
ARRAY_FILTER_USE_BOTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \CheckResult[] $aResults
|
||||
* @return string[]
|
||||
* @uses \CheckResult::__toString
|
||||
*
|
||||
* @since 2.7.1 2.8.0 N°2214
|
||||
*/
|
||||
public static function FromObjetsToStrings($aResults)
|
||||
{
|
||||
return array_map(function($value) {
|
||||
return $value->__toString();
|
||||
}, $aResults);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -413,37 +370,6 @@ class SetupUtils
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \CLIPage $oCliPage
|
||||
* @param int $iExitCode
|
||||
*
|
||||
* @since 2.7.1 2.8.0 N°2214
|
||||
*/
|
||||
public static function CheckPhpAndExtensionsForCli($oCliPage, $iExitCode = -1)
|
||||
{
|
||||
$aPhpCheckResults = self::CheckPhpAndExtensions();
|
||||
$aPhpCheckErrors = CheckResult::KeepOnlyErrors($aPhpCheckResults);
|
||||
if (empty($aPhpCheckErrors))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sMessageTitle = 'Error: PHP minimum requirements are not met !';
|
||||
$oCliPage->p($sMessageTitle);
|
||||
$aPhpCheckErrorsForPrint = CheckResult::FromObjetsToStrings($aPhpCheckErrors);
|
||||
foreach ($aPhpCheckErrorsForPrint as $sError)
|
||||
{
|
||||
$oCliPage->p(' * '.$sError);
|
||||
}
|
||||
$oCliPage->output();
|
||||
|
||||
// some CLI scripts are launched automatically
|
||||
// we need a log so that we don't miss errors after migration !
|
||||
IssueLog::Error($oCliPage->s_title.' '.$sMessageTitle, 'CLI', $aPhpCheckErrorsForPrint);
|
||||
|
||||
exit($iExitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CheckResult[] $aResult checks log
|
||||
*/
|
||||
|
||||
@@ -72,7 +72,6 @@ function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter = 'parameter')
|
||||
if (utils::IsModeCLI())
|
||||
{
|
||||
$oP = new CLIPage(Dict::S("TitleSynchroExecution"));
|
||||
SetupUtils::CheckPhpAndExtensionsForCli($oP, -2);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -255,7 +255,6 @@ class CLILikeWebPage extends WebPage
|
||||
if (utils::IsModeCLI())
|
||||
{
|
||||
$oP = new CLIPage(Dict::S('TitleSynchroExecution'));
|
||||
SetupUtils::CheckPhpAndExtensionsForCli($oP, -2);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter = 'parameter')
|
||||
|
||||
function UsageAndExit($oP)
|
||||
{
|
||||
$bModeCLI = ($oP instanceof CLIPage);
|
||||
$bModeCLI = utils::IsModeCLI();
|
||||
|
||||
if ($bModeCLI)
|
||||
{
|
||||
@@ -477,12 +477,9 @@ function ReorderProcesses(&$aProcesses, $aTasks, $oNow, $bVerbose, &$oP)
|
||||
|
||||
set_time_limit(0); // Some background actions may really take long to finish (like backup)
|
||||
|
||||
$bIsModeCLI = utils::IsModeCLI();
|
||||
if ($bIsModeCLI)
|
||||
if (utils::IsModeCLI())
|
||||
{
|
||||
$oP = new CLIPage("iTop - cron");
|
||||
|
||||
SetupUtils::CheckPhpAndExtensionsForCli($oP, EXIT_CODE_FATAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -500,7 +497,7 @@ catch (Exception $e)
|
||||
exit(EXIT_CODE_FATAL);
|
||||
}
|
||||
|
||||
if ($bIsModeCLI)
|
||||
if (utils::IsModeCLI())
|
||||
{
|
||||
// Next steps:
|
||||
// specific arguments: 'csvfile'
|
||||
|
||||
@@ -32,12 +32,6 @@ 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())
|
||||
@@ -45,14 +39,14 @@ function ReportErrorAndExit($sErrorMessage)
|
||||
$oP = new CLIPage("iTop - Export");
|
||||
$oP->p('ERROR: '.$sErrorMessage);
|
||||
$oP->output();
|
||||
exit(EXIT_CODE_ERROR);
|
||||
exit(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$oP = new WebPage("iTop - Export");
|
||||
$oP->p('ERROR: '.$sErrorMessage);
|
||||
$oP->output();
|
||||
exit(EXIT_CODE_ERROR);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +58,7 @@ function ReportErrorAndUsage($sErrorMessage)
|
||||
$oP->p('ERROR: '.$sErrorMessage);
|
||||
Usage($oP);
|
||||
$oP->output();
|
||||
exit(EXIT_CODE_ERROR);
|
||||
exit(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -72,7 +66,7 @@ function ReportErrorAndUsage($sErrorMessage)
|
||||
$oP->p('ERROR: '.$sErrorMessage);
|
||||
Usage($oP);
|
||||
$oP->output();
|
||||
exit(EXIT_CODE_ERROR);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,8 +565,6 @@ 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
|
||||
@@ -581,7 +573,7 @@ if (utils::IsModeCLI())
|
||||
catch(Exception $e)
|
||||
{
|
||||
echo "Error: ".$e->GetMessage()."<br/>\n";
|
||||
exit(EXIT_CODE_FATAL);
|
||||
exit(-2);
|
||||
}
|
||||
|
||||
$sAuthUser = utils::ReadParam('auth_user', null, true /* Allow CLI */, 'raw_data');
|
||||
|
||||
@@ -29,11 +29,6 @@ require_once(APPROOT.'/application/excelexporter.class.inc.php');
|
||||
|
||||
require_once(APPROOT.'/application/startup.inc.php');
|
||||
|
||||
|
||||
const EXIT_CODE_ERROR = -1;
|
||||
const EXIT_CODE_FATAL = -2;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// Do this before loging, in order to allow setting user credentials from within the file
|
||||
@@ -42,15 +37,12 @@ try
|
||||
catch(Exception $e)
|
||||
{
|
||||
echo "Error: ".$e->GetMessage()."<br/>\n";
|
||||
exit(EXIT_CODE_FATAL);
|
||||
exit -2;
|
||||
}
|
||||
|
||||
if (utils::IsModeCLI())
|
||||
{
|
||||
$oP = new CLIPage("iTop - Export");
|
||||
SetupUtils::CheckPhpAndExtensionsForCli($oP, EXIT_CODE_FATAL);
|
||||
|
||||
$sAuthUser = utils::ReadParam('auth_user', null, true /* Allow CLI */, 'raw_data');
|
||||
$sAuthUser = utils::ReadParam('auth_user', null, true /* Allow CLI */, 'raw_data');
|
||||
$sAuthPwd = utils::ReadParam('auth_pwd', null, true /* Allow CLI */, 'raw_data');
|
||||
|
||||
if (UserRights::CheckCredentials($sAuthUser, $sAuthPwd))
|
||||
@@ -59,9 +51,10 @@ if (utils::IsModeCLI())
|
||||
}
|
||||
else
|
||||
{
|
||||
$oP->p("Access restricted or wrong credentials ('$sAuthUser')");
|
||||
$oP = new CLIPage("iTop - Export");
|
||||
$oP->p("Access restricted or wrong credentials ('$sAuthUser')");
|
||||
$oP->output();
|
||||
exit(EXIT_CODE_ERROR);
|
||||
exit -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -81,7 +74,7 @@ if (utils::IsArchiveMode() && !UserRights::CanBrowseArchive())
|
||||
$oP = new CLIPage("iTop - Export");
|
||||
$oP->p("The user account is not authorized to access the archives");
|
||||
$oP->output();
|
||||
exit(EXIT_CODE_ERROR);
|
||||
exit -1;
|
||||
}
|
||||
|
||||
$bLocalize = (utils::ReadParam('no_localize', 0) != 1);
|
||||
|
||||
@@ -212,7 +212,6 @@ function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter)
|
||||
if (utils::IsModeCLI())
|
||||
{
|
||||
$oP = new CLIPage("iTop - Bulk import");
|
||||
SetupUtils::CheckPhpAndExtensionsForCli($oP, -2);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user