mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-27 04:28:44 +02:00
N°8796 - Add PHP code style validation in iTop and extensions - format whole code base
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2025 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
@@ -17,24 +18,25 @@ use utils;
|
||||
|
||||
class ConfigEditorController extends Controller
|
||||
{
|
||||
public const ROUTE_NAMESPACE = 'config_editor';
|
||||
public const MODULE_NAME = "itop-config";
|
||||
public const ROUTE_NAMESPACE = 'config_editor';
|
||||
public const MODULE_NAME = "itop-config";
|
||||
protected array $aWarnings = [];
|
||||
protected array $aInfo = [];
|
||||
protected array $aErrors = [];
|
||||
protected array $aSuccesses = [];
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(MODULESROOT.static::MODULE_NAME.'/templates', static::MODULE_NAME);
|
||||
}
|
||||
|
||||
public function OperationEdit() : void
|
||||
{
|
||||
public function OperationEdit(): void
|
||||
{
|
||||
$bShowEditor = true;
|
||||
$sConfigChecksum = '';
|
||||
$sCurrentConfig = '';
|
||||
|
||||
try {
|
||||
try {
|
||||
$sOperation = utils::ReadParam('edit_operation');
|
||||
if (MetaModel::GetConfig()->Get('demo_mode')) {
|
||||
throw new Exception(Dict::S('config-not-allowed-in-demo'), iTopConfigValidator::CONFIG_INFO);
|
||||
@@ -52,8 +54,7 @@ class ConfigEditorController extends Controller
|
||||
try {
|
||||
if ($sOperation == 'revert') {
|
||||
$this->AddAlert(Dict::S('config-reverted'), iTopConfigValidator::CONFIG_WARNING);
|
||||
}
|
||||
else if ($sOperation == 'save') {
|
||||
} elseif ($sOperation == 'save') {
|
||||
$sTransactionId = utils::ReadParam('transaction_id', '', false, 'transaction_id');
|
||||
if (!utils::IsTransactionValid($sTransactionId)) {
|
||||
throw new Exception(Dict::S('config-error-transaction'), iTopConfigValidator::CONFIG_ERROR);
|
||||
@@ -99,24 +100,21 @@ class ConfigEditorController extends Controller
|
||||
|
||||
$this->AddAlert($oValidator->CheckAsyncTasksRetryConfig($oTempConfig), iTopConfigValidator::CONFIG_WARNING);
|
||||
|
||||
|
||||
// Read the config from disk after save
|
||||
$sCurrentConfig = file_get_contents($sConfigFile);
|
||||
$sConfigChecksum = md5($sCurrentConfig);
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->AddAlertFromException($e);
|
||||
}
|
||||
|
||||
$this->AddAceScripts();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$bShowEditor = false;
|
||||
$this->AddAlertFromException($e);
|
||||
}
|
||||
|
||||
// display page
|
||||
// display page
|
||||
$this->DisplayPage([
|
||||
'aErrors' => $this->aErrors,
|
||||
'aWarnings' => $this->aWarnings,
|
||||
@@ -127,7 +125,7 @@ class ConfigEditorController extends Controller
|
||||
'sChecksum' => $sConfigChecksum,
|
||||
'sPrevConfig' => $sCurrentConfig,
|
||||
'sNewConfig' => $sCurrentConfig,
|
||||
]);
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,7 +141,6 @@ class ConfigEditorController extends Controller
|
||||
$this->AddLinkedScript(utils::GetAbsoluteUrlAppRoot().$sAceDir.'ext-searchbox.js');
|
||||
}
|
||||
|
||||
|
||||
public function AddAlertFromException(Exception $e): void
|
||||
{
|
||||
$this->AddAlert($e->getMessage(), $e->getCode());
|
||||
@@ -158,18 +155,18 @@ class ConfigEditorController extends Controller
|
||||
return;
|
||||
}
|
||||
switch ($iLevel) {
|
||||
case iTopConfigValidator::CONFIG_SUCCESS :
|
||||
case iTopConfigValidator::CONFIG_SUCCESS:
|
||||
$this->aSuccesses[] = $sMessage;
|
||||
break;
|
||||
case iTopConfigValidator::CONFIG_WARNING :
|
||||
case iTopConfigValidator::CONFIG_WARNING:
|
||||
$this->aWarnings[] = $sMessage;
|
||||
break;
|
||||
case iTopConfigValidator::CONFIG_INFO :
|
||||
case iTopConfigValidator::CONFIG_INFO:
|
||||
$this->aInfo[] = $sMessage;
|
||||
break;
|
||||
default :
|
||||
default:
|
||||
$this->aErrors[] = $sMessage;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user