diff --git a/datamodels/2.x/itop-core-update/ajax.php b/datamodels/2.x/itop-core-update/ajax.php deleted file mode 100644 index bfa81c538..000000000 --- a/datamodels/2.x/itop-core-update/ajax.php +++ /dev/null @@ -1,33 +0,0 @@ -DisableInDemoMode(); -$oUpdateController->AllowOnlyAdmin(); -$oUpdateController->HandleAjaxOperation(); - -unset($oCtxCoreUpdate); diff --git a/datamodels/2.x/itop-core-update/css/itop-core-update.scss b/datamodels/2.x/itop-core-update/css/itop-core-update.scss index 603c4bcb4..4ecdc2041 100644 --- a/datamodels/2.x/itop-core-update/css/itop-core-update.scss +++ b/datamodels/2.x/itop-core-update/css/itop-core-update.scss @@ -1,19 +1,6 @@ /*! - * Copyright (C) 2013-2023 Combodo SARL - * - * This file is part of iTop. - * - * iTop is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * iTop is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License + * @copyright Copyright (C) 2010-2023 Combodo SARL + * @license http://opensource.org/licenses/AGPL-3.0 */ $link-hover-color: #EA7D1E !default; @@ -30,61 +17,6 @@ fieldset { } } -.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { - background: #555555; - border: 1px solid #555555; - color: #EEEEEE; - font-weight: bold; -} -.ui-button:hover, .ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, -.ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-focus .ui-state-focus { - background: $link-hover-color; - border: 1px solid $link-hover-color; - color: #EEEEEE; - font-weight: bold; -} -.ui-button:disabled, .ui-button:disabled:hover { - background: #55555533; - border: 1px solid #55555533; - color: #EEEEEE; - font-weight: bold; -} -.ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br { - border-bottom-right-radius: 0; -} -.ui-corner-all, .ui-corner-bottom, .ui-corner-left, .ui-corner-bl { - border-bottom-left-radius: 0; -} -.ui-corner-all, .ui-corner-top, .ui-corner-right, .ui-corner-tr { - border-top-right-radius: 0; -} -.ui-corner-all, .ui-corner-top, .ui-corner-left, .ui-corner-tl { - border-top-left-radius: 0; -} -.ui-widget { - font-family: Verdana,Arial,sans-serif; - font-size: 1.1em; -} -.ui-button, .ui-button:link, .ui-button:visited, .ui-button:hover, .ui-button:active { - padding: 0.3em 1em; - text-decoration: none; -} -.ui-button { - cursor: pointer; - display: inline-block; - line-height: normal; - margin-right: 0.1em; - overflow: visible; - position: relative; - text-align: center; - vertical-align: middle; -} - -.form-inline { - display: inline-block; - margin-top: 13px; -} - #progress { margin: 5px auto; display:block; diff --git a/datamodels/2.x/itop-core-update/datamodel.itop-core-update.xml b/datamodels/2.x/itop-core-update/datamodel.itop-core-update.xml index 3f9c13af9..9dccf93a9 100644 --- a/datamodels/2.x/itop-core-update/datamodel.itop-core-update.xml +++ b/datamodels/2.x/itop-core-update/datamodel.itop-core-update.xml @@ -4,7 +4,7 @@
diff --git a/datamodels/2.x/itop-core-update/index.php b/datamodels/2.x/itop-core-update/index.php deleted file mode 100644 index 228a1578b..000000000 --- a/datamodels/2.x/itop-core-update/index.php +++ /dev/null @@ -1,21 +0,0 @@ -DisableInDemoMode(); -$oUpdateController->AllowOnlyAdmin(); -$oUpdateController->SetDefaultOperation('SelectUpdateFile'); -$oUpdateController->HandleOperation(); - -unset($oCtxCoreUpdate); diff --git a/datamodels/2.x/itop-core-update/module.itop-core-update.php b/datamodels/2.x/itop-core-update/module.itop-core-update.php index 299ef532f..c48960510 100644 --- a/datamodels/2.x/itop-core-update/module.itop-core-update.php +++ b/datamodels/2.x/itop-core-update/module.itop-core-update.php @@ -25,7 +25,7 @@ SetupWebPage::AddModule( __FILE__, // Path to the current file, all other file names are relative to the directory containing this file 'itop-core-update/3.1.0', - array( + [ // Identification // 'label' => 'iTop Core Update', @@ -33,25 +33,25 @@ SetupWebPage::AddModule( // Setup // - 'dependencies' => array( + 'dependencies' => [ 'itop-files-information/2.7.0', 'combodo-db-tools/2.7.0', - ), + ], 'mandatory' => false, 'visible' => true, // Components // - 'datamodel' => array( + 'datamodel' => [ 'model.itop-core-update.php', 'src/Service/RunTimeEnvironmentCoreUpdater.php', 'src/Service/CoreUpdater.php', 'src/Controller/UpdateController.php', 'src/Controller/AjaxController.php', - ), - 'webservice' => array(), - 'data.struct' => array(), - 'data.sample' => array(), + ], + 'webservice' => [], + 'data.struct' => [], + 'data.sample' => [], // Documentation // @@ -60,6 +60,6 @@ SetupWebPage::AddModule( // Default settings // - 'settings' => array(), - ) + 'settings' => [], + ] ); diff --git a/datamodels/2.x/itop-core-update/pt_br.dict.itop-core-update.php b/datamodels/2.x/itop-core-update/pt_br.dict.itop-core-update.php deleted file mode 100644 index be06eb5b7..000000000 --- a/datamodels/2.x/itop-core-update/pt_br.dict.itop-core-update.php +++ /dev/null @@ -1,120 +0,0 @@ - - */ -Dict::Add('PT BR', 'Brazilian', 'Brazilian', array( - 'iTopUpdate:UI:PageTitle' => 'Application Upgrade~~', - 'itop-core-update:UI:SelectUpdateFile' => 'Application Upgrade~~', - 'itop-core-update:UI:ConfirmUpdate' => 'Application Upgrade~~', - 'itop-core-update:UI:UpdateCoreFiles' => 'Application Upgrade~~', - 'iTopUpdate:UI:MaintenanceModeActive' => 'The application is currently under maintenance, no user can access the application. You have to run a setup or restore the application archive to return in normal mode.~~', - 'itop-core-update:UI:UpdateDone' => 'Application Upgrade~~', - - 'itop-core-update/Operation:SelectUpdateFile/Title' => 'Application Upgrade~~', - 'itop-core-update/Operation:ConfirmUpdate/Title' => 'Confirm Application Upgrade~~', - 'itop-core-update/Operation:UpdateCoreFiles/Title' => 'Application Upgrading~~', - 'itop-core-update/Operation:UpdateDone/Title' => 'Application Upgrade Done~~', - - 'iTopUpdate:UI:SelectUpdateFile' => 'Select an upgrade file to upload~~', - 'iTopUpdate:UI:CheckUpdate' => 'Verify upgrade file~~', - 'iTopUpdate:UI:ConfirmInstallFile' => 'You are about to install %1$s~~', - 'iTopUpdate:UI:DoUpdate' => 'Upgrade~~', - 'iTopUpdate:UI:CurrentVersion' => 'Current installed version~~', - 'iTopUpdate:UI:NewVersion' => 'Newly installed version~~', - 'iTopUpdate:UI:Back' => 'Back~~', - 'iTopUpdate:UI:Cancel' => 'Cancel~~', - 'iTopUpdate:UI:Continue' => 'Continue~~', - 'iTopUpdate:UI:RunSetup' => 'Run Setup~~', - 'iTopUpdate:UI:WithDBBackup' => 'Database backup~~', - 'iTopUpdate:UI:WithFilesBackup' => 'Application files backup~~', - 'iTopUpdate:UI:WithoutBackup' => 'No backup is planned~~', - 'iTopUpdate:UI:Backup' => 'Backup generated before update~~', - 'iTopUpdate:UI:DoFilesArchive' => 'Archive application files~~', - 'iTopUpdate:UI:UploadArchive' => 'Select a package to upload~~', - 'iTopUpdate:UI:ServerFile' => 'Path of a package already on the server~~', - 'iTopUpdate:UI:WarningReadOnlyDuringUpdate' => 'During the upgrade, the application will be read-only.~~', - - 'iTopUpdate:UI:Status' => 'Status~~', - 'iTopUpdate:UI:Action' => 'Update~~', - 'iTopUpdate:UI:History' => 'Versions History~~', - 'iTopUpdate:UI:Progress' => 'Progress of the upgrade~~', - - 'iTopUpdate:UI:DoBackup:Label' => 'Backup files and database~~', - 'iTopUpdate:UI:DoBackup:Warning' => 'Backup is not recommended due to limited available disk space~~', - - 'iTopUpdate:UI:DiskFreeSpace' => 'Disk free space~~', - 'iTopUpdate:UI:ItopDiskSpace' => 'iTop disk space~~', - 'iTopUpdate:UI:DBDiskSpace' => 'Database disk space~~', - 'iTopUpdate:UI:FileUploadMaxSize' => 'File upload max size~~', - - 'iTopUpdate:UI:PostMaxSize' => 'PHP ini value post_max_size: %1$s~~', - 'iTopUpdate:UI:UploadMaxFileSize' => 'PHP ini value upload_max_filesize: %1$s~~', - - 'iTopUpdate:UI:CanCoreUpdate:Loading' => 'Checking filesystem~~', - 'iTopUpdate:UI:CanCoreUpdate:Error' => 'Checking filesystem failed (%1$s)~~', - 'iTopUpdate:UI:CanCoreUpdate:ErrorFileNotExist' => 'Checking filesystem failed (File not exist %1$s)~~', - 'iTopUpdate:UI:CanCoreUpdate:Failed' => 'Checking filesystem failed~~', - 'iTopUpdate:UI:CanCoreUpdate:Yes' => 'Application can be updated~~', - 'iTopUpdate:UI:CanCoreUpdate:No' => 'Application cannot be updated: %1$s~~', - 'iTopUpdate:UI:CanCoreUpdate:Warning' => 'Warning: application update can fail: %1$s~~', - 'iTopUpdate:UI:CannotUpdateUseSetup' => 'Some modified files were detected, a partial update cannot be executed.Follow the procedure in order to manually upgrade your iTop. You must use the setup to update the application.~~', - 'iTopUpdate:UI:CheckInProgress'=>'Please wait during integrity check~~', - - // Setup Messages - 'iTopUpdate:UI:SetupMessage:Ready' => 'Ready to start~~', - 'iTopUpdate:UI:SetupMessage:EnterMaintenance' => 'Entering maintenance mode~~', - 'iTopUpdate:UI:SetupMessage:Backup' => 'Database backup~~', - 'iTopUpdate:UI:SetupMessage:FilesArchive' => 'Archive application files~~', - 'iTopUpdate:UI:SetupMessage:CopyFiles' => 'Copy new version files~~', - 'iTopUpdate:UI:SetupMessage:CheckCompile' => 'Check application upgrade~~', - 'iTopUpdate:UI:SetupMessage:Compile' => 'Upgrade application and database~~', - 'iTopUpdate:UI:SetupMessage:UpdateDatabase' => 'Upgrade database~~', - 'iTopUpdate:UI:SetupMessage:ExitMaintenance' => 'Exiting maintenance mode~~', - 'iTopUpdate:UI:SetupMessage:UpdateDone' => 'Upgrade completed~~', - - // Errors - 'iTopUpdate:Error:MissingFunction' => 'Impossible to start upgrade, missing function~~', - 'iTopUpdate:Error:MissingFile' => 'Missing file: %1$s~~', - 'iTopUpdate:Error:CorruptedFile' => 'File %1$s is corrupted~~', - 'iTopUpdate:Error:BadFileFormat' => 'Upgrade file is not a zip file~~', - 'iTopUpdate:Error:BadFileContent' => 'Upgrade file is not an application archive~~', - 'iTopUpdate:Error:BadItopProduct' => 'Upgrade file is not compatible with your application~~', - 'iTopUpdate:Error:Copy' => 'Error, cannot copy \'%1$s\' to \'%2$s\'~~', - 'iTopUpdate:Error:FileNotFound' => 'File not found~~', - 'iTopUpdate:Error:NoFile' => 'No file provided~~', - 'iTopUpdate:Error:InvalidToken' => 'Invalid token~~', - 'iTopUpdate:Error:UpdateFailed' => 'Upgrade failed ~~', - 'iTopUpdate:Error:FileUploadMaxSizeTooSmall' => 'The upload max size seems too small for update. Please change the PHP configuration.~~', - - 'iTopUpdate:UI:RestoreArchive' => 'You can restore your application from the archive \'%1$s\'~~', - 'iTopUpdate:UI:RestoreBackup' => 'You can restore the database from \'%1$s\'~~', - 'iTopUpdate:UI:UpdateDone' => 'Upgrade successful~~', - 'Menu:iTopUpdate' => 'Application upgrade~~', - 'Menu:iTopUpdate+' => 'Application upgrade~~', - - // Missing itop entries - 'Class:ModuleInstallation/Attribute:installed' => 'Installed on~~', - 'Class:ModuleInstallation/Attribute:name' => 'Name~~', - 'Class:ModuleInstallation/Attribute:version' => 'Version~~', - 'Class:ModuleInstallation/Attribute:comment' => 'Comment~~', -)); - - diff --git a/datamodels/2.x/itop-core-update/src/Controller/AjaxController.php b/datamodels/2.x/itop-core-update/src/Controller/AjaxController.php index 0c276ec97..6a8cd42e5 100644 --- a/datamodels/2.x/itop-core-update/src/Controller/AjaxController.php +++ b/datamodels/2.x/itop-core-update/src/Controller/AjaxController.php @@ -13,6 +13,7 @@ use Combodo\iTop\CoreUpdate\Service\CoreUpdater; use Combodo\iTop\DBTools\Service\DBToolsUtils; use Combodo\iTop\FilesInformation\Service\FileNotExistException; use Combodo\iTop\FilesInformation\Service\FilesInformation; +use ContextTag; use Dict; use Exception; use IssueLog; @@ -23,9 +24,45 @@ use utils; class AjaxController extends Controller { + public const ROUTE_NAMESPACE = 'core_update_ajax'; + protected $oCtxCoreUpdate; + + /** + * @param $sViewPath + * @param $sModuleName + * @param $aAdditionalPaths + * + * @throws \ConfigException + * @throws \CoreException + * @throws \DictExceptionUnknownLanguage + * @throws \MySQLException + */ + public function __construct($sViewPath = '', $sModuleName = 'core', $aAdditionalPaths = []) + { + if (!defined('MODULESROOT')) + { + define('MODULESROOT', APPROOT.'env-production/'); + } + + require_once(MODULESROOT.'itop-core-update/src/Service/RunTimeEnvironmentCoreUpdater.php'); + require_once(MODULESROOT.'itop-core-update/src/Service/CoreUpdater.php'); + require_once(MODULESROOT.'itop-core-update/src/Controller/AjaxController.php'); + + MetaModel::LoadConfig(utils::GetConfig()); + + $sViewPath = MODULESROOT.'itop-core-update/templates'; + $sModuleName = 'itop-core-update'; + parent::__construct($sViewPath, $sModuleName, $aAdditionalPaths); + + $this->DisableInDemoMode(); + $this->AllowOnlyAdmin(); + $this->CheckAccess(); + $this->oCtxCoreUpdate = new ContextTag(ContextTag::TAG_SETUP); + } + public function OperationCanUpdateCore() { - $aParams = array(); + $aParams = []; try { @@ -58,7 +95,7 @@ class AjaxController extends Controller public function OperationGetItopDiskSpace() { - $aParams = array(); + $aParams = []; $aParams['iItopDiskSpace'] = FilesInformation::GetItopDiskSpace(); $aParams['sItopDiskSpace'] = utils::BytesToFriendlyFormat($aParams['iItopDiskSpace']); $this->DisplayJSONPage($aParams); @@ -66,7 +103,7 @@ class AjaxController extends Controller public function OperationGetDBDiskSpace() { - $aParams = array(); + $aParams = []; $aParams['iDBDiskSpace'] = DBToolsUtils::GetDatabaseSize(); $aParams['sDBDiskSpace'] = utils::BytesToFriendlyFormat($aParams['iDBDiskSpace']); $this->DisplayJSONPage($aParams); @@ -74,14 +111,14 @@ class AjaxController extends Controller public function OperationGetCurrentVersion() { - $aParams = array(); + $aParams = []; $aParams['sVersion'] = Dict::Format('UI:iTopVersion:Long', ITOP_APPLICATION, ITOP_VERSION, ITOP_REVISION, ITOP_BUILD_DATE); $this->DisplayJSONPage($aParams); } public function OperationEnterMaintenance() { - $aParams = array(); + $aParams = []; try { SetupUtils::CheckSetupToken(); @@ -98,7 +135,7 @@ class AjaxController extends Controller public function OperationExitMaintenance() { - $aParams = array(); + $aParams = []; try { SetupUtils::CheckSetupToken(true); @@ -115,7 +152,7 @@ class AjaxController extends Controller public function OperationBackup() { - $aParams = array(); + $aParams = []; try { SetupUtils::CheckSetupToken(); @@ -132,7 +169,7 @@ class AjaxController extends Controller public function OperationFilesArchive() { - $aParams = array(); + $aParams = []; try { SetupUtils::CheckSetupToken(); @@ -149,7 +186,7 @@ class AjaxController extends Controller public function OperationCopyFiles() { - $aParams = array(); + $aParams = []; try { SetupUtils::CheckSetupToken(); @@ -167,7 +204,7 @@ class AjaxController extends Controller public function OperationCheckCompile() { - $aParams = array(); + $aParams = []; try { SetupUtils::CheckSetupToken(); @@ -186,7 +223,7 @@ class AjaxController extends Controller public function OperationCompile() { - $aParams = array(); + $aParams = []; try { SetupUtils::CheckSetupToken(); @@ -205,7 +242,7 @@ class AjaxController extends Controller public function OperationUpdateDatabase() { - $aParams = array(); + $aParams = []; try { SetupUtils::CheckSetupToken(); diff --git a/datamodels/2.x/itop-core-update/src/Controller/UpdateController.php b/datamodels/2.x/itop-core-update/src/Controller/UpdateController.php index 8f9ce995a..de2ddf5e7 100644 --- a/datamodels/2.x/itop-core-update/src/Controller/UpdateController.php +++ b/datamodels/2.x/itop-core-update/src/Controller/UpdateController.php @@ -1,7 +1,7 @@ DisableInDemoMode(); + $this->AllowOnlyAdmin(); + $this->CheckAccess(); + } + public function OperationSelectUpdateFile() { $sTransactionId = utils::GetNewTransactionId(); $aParams = []; $aParams['sTransactionId'] = $sTransactionId; - //$aParams['aPreviousInstall'] = $this->GetPreviousInstallations(); - $aParams['sAjaxURL'] = utils::GetAbsoluteUrlModulePage('itop-core-update', 'ajax.php', array('maintenance' => 'true')); + $aParams['sAjaxURL'] = utils::GetAbsoluteUrlAppRoot().'/pages/UI.php'; $aParams['iDiskFreeSpace'] = disk_free_space(APPROOT); $aParams['sDiskFreeSpace'] = utils::BytesToFriendlyFormat($aParams['iDiskFreeSpace']); $aParams['iFileUploadMaxSize'] = $this->GetFileUploadMaxSize(); @@ -46,15 +60,11 @@ class UpdateController extends Controller } $aParams['bIsSetupLaunchButtonEnabled'] = $bIsSetupLaunchButtonEnabled; if ($bIsSetupLaunchButtonEnabled) { - $sLaunchSetupUrl = utils::GetAbsoluteUrlModulePage('itop-core-update', 'ajax.php', - [ - 'operation' => 'LaunchSetup', - 'transaction_id' => $sTransactionId, - ]);; + $sLaunchSetupUrl = Router::GetInstance()->GenerateUrl('core_update_ajax.launch_setup', ['transaction_id' => $sTransactionId]); $aParams['sLaunchSetupUrl'] = $sLaunchSetupUrl; } - $this->DisplayPage($aParams); + $this->DisplayPage($aParams, 'SelectUpdateFile'); } /** @@ -63,108 +73,94 @@ class UpdateController extends Controller public function OperationConfirmUpdate() { $sTransactionId = utils::ReadPostedParam('transaction_id', '', 'transaction_id'); - if (!utils::IsTransactionValid($sTransactionId)) - { + if (!utils::IsTransactionValid($sTransactionId)) { throw new Exception(Dict::S('iTopUpdate:Error:InvalidToken')); } $bDoBackup = utils::ReadPostedParam('doBackup', 0, 'integer') == 1; $bDoFilesArchive = utils::ReadPostedParam('doFilesArchive', 0, 'integer') == 1; - $sNewVersion = null; $sName = ''; - $sVersionToInstall = ''; - $sError = ''; - try - { - if (isset($_FILES['file'])) - { - $aFileInfo = $_FILES['file']; - $iError = $aFileInfo['error']; - if ($iError === UPLOAD_ERR_OK) - { - $sDownloadDir = CoreUpdater::DOWNLOAD_DIR; - if (is_dir($sDownloadDir)) - { - SetupUtils::rrmdir($sDownloadDir); - } - SetupUtils::builddir($sDownloadDir); - $sTmpName = $aFileInfo['tmp_name']; - $sName = $aFileInfo['name']; - $sNewVersion = $sDownloadDir.$sName; - if (@move_uploaded_file($sTmpName, $sNewVersion) === false) - { - throw new Exception(Dict::S('iTopUpdate:Error:FileNotFound')); - } - CoreUpdater::ExtractDownloadedFile($sNewVersion); - $sVersionToInstall = CoreUpdater::GetVersionToInstall(); - } - else - { - throw new Exception(Dict::S('iTopUpdate:Error:NoFile')); - } - } - else - { - throw new Exception(Dict::S('iTopUpdate:Error:NoFile')); - } - } - catch (Exception $e) - { - $iError = UPLOAD_ERR_NO_FILE; - $sError = $e->getMessage(); - } + $sVersionToInstall = ''; + $sError = ''; + try { + if (isset($_FILES['file'])) { + $aFileInfo = $_FILES['file']; + $iError = $aFileInfo['error']; + if ($iError === UPLOAD_ERR_OK) { + $sDownloadDir = CoreUpdater::DOWNLOAD_DIR; + if (is_dir($sDownloadDir)) { + SetupUtils::rrmdir($sDownloadDir); + } + SetupUtils::builddir($sDownloadDir); + $sTmpName = $aFileInfo['tmp_name']; + $sName = $aFileInfo['name']; + $sNewVersion = $sDownloadDir.$sName; + if (@move_uploaded_file($sTmpName, $sNewVersion) === false) { + throw new Exception(Dict::S('iTopUpdate:Error:FileNotFound')); + } + CoreUpdater::ExtractDownloadedFile($sNewVersion); + $sVersionToInstall = CoreUpdater::GetVersionToInstall(); + } else { + throw new Exception(Dict::S('iTopUpdate:Error:NoFile')); + } + } else { + throw new Exception(Dict::S('iTopUpdate:Error:NoFile')); + } + } + catch (Exception $e) { + $iError = UPLOAD_ERR_NO_FILE; + $sError = $e->getMessage(); + } - - $aParams = array(); - $aParams['sName'] = $sName; - $aParams['bSuccess'] = ($iError == 0); - $aParams['sError'] = $sError; + $aParams = []; + $aParams['sName'] = $sName; + $aParams['bSuccess'] = ($iError == 0); + $aParams['sError'] = $sError; $aParams['bDoBackup'] = $bDoBackup; $aParams['bDoFilesArchive'] = $bDoFilesArchive; - $aParams['sItopArchive'] = CoreUpdater::GetItopArchiveFile(); - $aParams['sBackupFile'] = CoreUpdater::GetBackupFile(); + $aParams['sItopArchive'] = CoreUpdater::GetItopArchiveFile(); + $aParams['sBackupFile'] = CoreUpdater::GetBackupFile(); - $sQuestion = Dict::Format('iTopUpdate:UI:ConfirmInstallFile', $sVersionToInstall); + $sQuestion = Dict::Format('iTopUpdate:UI:ConfirmInstallFile', $sVersionToInstall); $aParams['sQuestion'] = $sQuestion; - $sTransactionId = utils::GetNewTransactionId(); + $sTransactionId = utils::GetNewTransactionId(); $aParams['sTransactionId'] = $sTransactionId; $this->AddSaas('env-'.utils::GetCurrentEnvironment().'/itop-core-update/css/itop-core-update.scss'); - $this->DisplaySetupPage($aParams); + $this->DisplaySetupPage($aParams, 'ConfirmUpdate'); } public function OperationUpdateCoreFiles() - { - $sTransactionId = utils::ReadPostedParam('transaction_id', '', 'transaction_id'); - if (!utils::IsTransactionValid($sTransactionId)) - { - throw new Exception(Dict::S('iTopUpdate:Error:InvalidToken')); - } + { + $sTransactionId = utils::ReadPostedParam('transaction_id', '', 'transaction_id'); + if (!utils::IsTransactionValid($sTransactionId)) { + throw new Exception(Dict::S('iTopUpdate:Error:InvalidToken')); + } - $sNewVersion = utils::ReadPostedParam('filename', null, 'filename'); - $bDoBackup = utils::ReadPostedParam('doBackup', 0, 'integer') == 1; + $sNewVersion = utils::ReadPostedParam('filename', null, 'filename'); + $bDoBackup = utils::ReadPostedParam('doBackup', 0, 'integer') == 1; $bDoFilesArchive = utils::ReadPostedParam('doFilesArchive', 0, 'integer') == 1; - $sCurrentVersion = Dict::Format('UI:iTopVersion:Long', ITOP_APPLICATION, ITOP_VERSION, ITOP_REVISION, ITOP_BUILD_DATE); + $sCurrentVersion = Dict::Format('UI:iTopVersion:Long', ITOP_APPLICATION, ITOP_VERSION, ITOP_REVISION, ITOP_BUILD_DATE); - $aParams = array( - 'sCurrentVersion' => $sCurrentVersion, - 'bDoBackup' => $bDoBackup, - 'sBackupFile' => CoreUpdater::GetBackupFile(), + $aParams = [ + 'sCurrentVersion' => $sCurrentVersion, + 'bDoBackup' => $bDoBackup, + 'sBackupFile' => CoreUpdater::GetBackupFile(), 'bDoFilesArchive' => $bDoFilesArchive, - 'sItopArchive' => CoreUpdater::GetItopArchiveFile(), - 'sNewVersion' => $sNewVersion, - 'sProgressImage' => utils::GetAbsoluteUrlAppRoot().'setup/orange-progress.gif', - 'sSetupToken' => SetupUtils::CreateSetupToken(), - 'sAjaxURL' => utils::GetAbsoluteUrlModulePage('itop-core-update', 'ajax.php', array('maintenance' => 'true')), - ); - $this->AddLinkedScript(utils::GetAbsoluteUrlAppRoot().'setup/jquery.progression.js'); - $this->AddSaas('env-'.utils::GetCurrentEnvironment().'/itop-core-update/css/itop-core-update.scss'); + 'sItopArchive' => CoreUpdater::GetItopArchiveFile(), + 'sNewVersion' => $sNewVersion, + 'sProgressImage' => utils::GetAbsoluteUrlAppRoot().'setup/orange-progress.gif', + 'sSetupToken' => SetupUtils::CreateSetupToken(), + 'sAjaxURL' => utils::GetAbsoluteUrlAppRoot().'/pages/UI.php', + ]; + $this->AddLinkedScript(utils::GetAbsoluteUrlAppRoot().'setup/jquery.progression.js'); + $this->AddSaas('env-'.utils::GetCurrentEnvironment().'/itop-core-update/css/itop-core-update.scss'); - $this->DisplaySetupPage($aParams); - } + $this->DisplaySetupPage($aParams, 'UpdateCoreFiles'); + } public function OperationRunSetup() { @@ -186,23 +182,21 @@ class UpdateController extends Controller { static $iMaxSize = -1; - if ($iMaxSize < 0) - { + if ($iMaxSize < 0) { // Start with post_max_size. $iPostMaxSize = $this->ParseSize(ini_get('post_max_size')); - if ($iPostMaxSize > 0) - { + if ($iPostMaxSize > 0) { $iMaxSize = $iPostMaxSize; } // If upload_max_size is less, then reduce. Except if upload_max_size is // zero, which indicates no limit. $iUploadMax = $this->ParseSize(ini_get('upload_max_filesize')); - if ($iUploadMax > 0 && $iUploadMax < $iMaxSize) - { + if ($iUploadMax > 0 && $iUploadMax < $iMaxSize) { $iMaxSize = $iUploadMax; } } + return $iMaxSize; } @@ -210,13 +204,10 @@ class UpdateController extends Controller { $sUnit = preg_replace('/[^bkmgtpezy]/i', '', $iSize); // Remove the non-unit characters from the size. $iSize = preg_replace('/[^0-9.]/', '', $iSize); // Remove the non-numeric characters from the size. - if ($sUnit) - { + if ($sUnit) { // Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by. return round($iSize * pow(1024, stripos('bkmgtpezy', $sUnit[0]))); - } - else - { + } else { return round($iSize); } } diff --git a/datamodels/2.x/itop-core-update/src/Service/CoreUpdater.php b/datamodels/2.x/itop-core-update/src/Service/CoreUpdater.php index 1c6f45fc5..bf9bbaabc 100644 --- a/datamodels/2.x/itop-core-update/src/Service/CoreUpdater.php +++ b/datamodels/2.x/itop-core-update/src/Service/CoreUpdater.php @@ -1,10 +1,7 @@ InitDataModel($oConfig, true); $sModulesDirToKeep = $oRuntimeEnv->GetBuildDir(); - $aDirsToScanForModules = array( + $aDirsToScanForModules = [ $sModulesDirToKeep, APPROOT.'extensions' - ); + ]; $aAvailableModules = $oRuntimeEnv->AnalyzeInstallation($oConfig, $aDirsToScanForModules); - $aSelectedModules = array(); + $aSelectedModules = []; foreach ($aAvailableModules as $sModuleId => $aModule) { if (($sModuleId == ROOT_MODULE) || ($sModuleId == DATAMODEL_MODULE)) @@ -209,7 +206,7 @@ final class CoreUpdater $oExtensionsMap->MarkAsChosen($oExtension->sCode); } } - $aSelectedExtensionCodes = array(); + $aSelectedExtensionCodes = []; foreach ($oExtensionsMap->GetChoices() as $oExtension) { $aSelectedExtensionCodes[] = $oExtension->sCode; @@ -569,7 +566,7 @@ final class CoreUpdater { throw new Exception(Dict::S(Dict::S('iTopUpdate:Error:BadFileContent'))); } - $aValues = array(); + $aValues = []; foreach ($aMatches['name'] as $index => $sName) { $aValues[$sName] = $aMatches['value'][$index]; diff --git a/datamodels/2.x/itop-core-update/view/ConfirmUpdate.html.twig b/datamodels/2.x/itop-core-update/templates/ConfirmUpdate.html.twig similarity index 97% rename from datamodels/2.x/itop-core-update/view/ConfirmUpdate.html.twig rename to datamodels/2.x/itop-core-update/templates/ConfirmUpdate.html.twig index c18abf0ae..417e46c33 100644 --- a/datamodels/2.x/itop-core-update/view/ConfirmUpdate.html.twig +++ b/datamodels/2.x/itop-core-update/templates/ConfirmUpdate.html.twig @@ -39,7 +39,7 @@ {% UIToolbarSpacer Standard {} %} {% UIForm Standard {'CSSClasses':['form-inline']} %} {% UIButton ForPrimaryAction {'sId':'do-update', 'sLabel':'iTopUpdate:UI:DoUpdate'|dict_s, 'bIsSubmit':true} %} - {% UIInput ForHidden {'sName':'operation', 'sValue':'UpdateCoreFiles'} %} + {% UIInput ForHidden {'sName':'route', 'sValue':'core_update.update_core_files'} %} {% UIInput ForHidden {'sName':'transaction_id', 'sValue':sTransactionId} %} {% UIInput ForHidden {'sName':'filename', 'sValue':sName} %} {% UIInput ForHidden {'sName':'doBackup', 'sValue':bDoBackup} %} diff --git a/datamodels/2.x/itop-core-update/view/ConfirmUpdate.ready.js.twig b/datamodels/2.x/itop-core-update/templates/ConfirmUpdate.ready.js.twig similarity index 100% rename from datamodels/2.x/itop-core-update/view/ConfirmUpdate.ready.js.twig rename to datamodels/2.x/itop-core-update/templates/ConfirmUpdate.ready.js.twig diff --git a/datamodels/2.x/itop-core-update/view/SelectUpdateFile.html.twig b/datamodels/2.x/itop-core-update/templates/SelectUpdateFile.html.twig similarity index 98% rename from datamodels/2.x/itop-core-update/view/SelectUpdateFile.html.twig rename to datamodels/2.x/itop-core-update/templates/SelectUpdateFile.html.twig index ac6a1bd45..3f677f5d9 100644 --- a/datamodels/2.x/itop-core-update/view/SelectUpdateFile.html.twig +++ b/datamodels/2.x/itop-core-update/templates/SelectUpdateFile.html.twig @@ -45,7 +45,7 @@ {% UIFieldSet Standard {'sLegend':'iTopUpdate:UI:SelectUpdateFile'|dict_s, 'sId':'form-update-outer'} %} {% UIForm Standard {} %} - {% UIInput ForHidden {'sName':'operation', 'sValue':'ConfirmUpdate'} %} + {% UIInput ForHidden {'sName':'route', 'sValue':'core_update.confirm_update'} %} {% UIInput ForHidden {'sName':'transaction_id', 'sValue':sTransactionId} %} {% UIAlert ForFailure {'sId':'header-file-size', 'IsHidden':true} %} diff --git a/datamodels/2.x/itop-core-update/view/SelectUpdateFile.ready.js.twig b/datamodels/2.x/itop-core-update/templates/SelectUpdateFile.ready.js.twig similarity index 93% rename from datamodels/2.x/itop-core-update/view/SelectUpdateFile.ready.js.twig rename to datamodels/2.x/itop-core-update/templates/SelectUpdateFile.ready.js.twig index 0b79a663c..eb1789412 100644 --- a/datamodels/2.x/itop-core-update/view/SelectUpdateFile.ready.js.twig +++ b/datamodels/2.x/itop-core-update/templates/SelectUpdateFile.ready.js.twig @@ -7,7 +7,8 @@ $.ajax({ method: "POST", url: "{{ sAjaxURL|raw }}", data: { - "operation": "CanUpdateCore" + route: "core_update_ajax.can_update_core", + maintenance: true }, dataType: "json", success: function (data) { @@ -39,7 +40,8 @@ var oGetItopDiskSpace = $.ajax({ method: "POST", url: "{{ sAjaxURL|raw }}", data: { - "operation": "GetItopDiskSpace" + route: "core_update_ajax.get_itop_disk_space", + maintenance: true }, dataType: "json", success: function(data) @@ -53,7 +55,8 @@ var oGetDBDiskSpace = $.ajax({ method: "POST", url: "{{ sAjaxURL|raw }}", data: { - "operation": "GetDBDiskSpace" + route: "core_update_ajax.get_d_b_disk_space", + maintenance: true }, dataType: "json", success: function(data) diff --git a/datamodels/2.x/itop-core-update/view/UpdateCoreFiles.html.twig b/datamodels/2.x/itop-core-update/templates/UpdateCoreFiles.html.twig similarity index 97% rename from datamodels/2.x/itop-core-update/view/UpdateCoreFiles.html.twig rename to datamodels/2.x/itop-core-update/templates/UpdateCoreFiles.html.twig index 097c8ca14..fdb86400f 100644 --- a/datamodels/2.x/itop-core-update/view/UpdateCoreFiles.html.twig +++ b/datamodels/2.x/itop-core-update/templates/UpdateCoreFiles.html.twig @@ -54,7 +54,7 @@ {% UIToolbar ForButton {'AddCSSClass':'ibo-setup--wizard--buttons-container'} %} {% UIContentBlock Standard {sId:'run_setup',aContainerClasses:['ibo-update-core--run-setup'], IsHidden:true} %} {% UIForm Standard {CSSClasses:['form-inline']} %} - {% UIInput ForHidden {sName:'operation', sValue:'RunSetup'} %} + {% UIInput ForHidden {sName:'route', sValue:'core_update.run_setup'} %} {% UIInput ForHidden {sName:'authent', sValue:sSetupToken} %} {% UIInput ForHidden {sName:'', sValue:''} %} {% UIButton ForPrimaryAction {sLabel:'iTopUpdate:UI:RunSetup'|dict_s, sId:'run_setup', bIsSubmit:true, IsDisabled:false} %} diff --git a/datamodels/2.x/itop-core-update/view/UpdateCoreFiles.ready.js.twig b/datamodels/2.x/itop-core-update/templates/UpdateCoreFiles.ready.js.twig similarity index 84% rename from datamodels/2.x/itop-core-update/view/UpdateCoreFiles.ready.js.twig rename to datamodels/2.x/itop-core-update/templates/UpdateCoreFiles.ready.js.twig index 6e0905716..0e6d3b85b 100644 --- a/datamodels/2.x/itop-core-update/view/UpdateCoreFiles.ready.js.twig +++ b/datamodels/2.x/itop-core-update/templates/UpdateCoreFiles.ready.js.twig @@ -15,7 +15,8 @@ var oGetCurrentVersion = { method: "POST", url: "{{ sAjaxURL|raw }}", data: { - "operation": "GetCurrentVersion" + route: "core_update_ajax.get_current_version", + maintenance: true }, dataType: "json", success: function(data) @@ -34,20 +35,21 @@ function GetAjaxRequest(sOperation) method: "POST", url: "{{ sAjaxURL|raw }}", data: { - "operation": sOperation, - "authent": "{{ sSetupToken }}" + route: sOperation, + authent: "{{ sSetupToken }}", + maintenance: true }, dataType: "json" }; - if (sOperation === "Backup") + if (sOperation === "core_update_ajax.backup") { oAjaxRequest.success = function() { $("#do_backup_done").removeClass("ibo-is-hidden"); }; } - if (sOperation === "FilesArchive") + if (sOperation === "core_update_ajax.files_archive") { oAjaxRequest.success = function() { $("#do_files_archive_done").removeClass("ibo-is-hidden"); @@ -67,15 +69,15 @@ aStepsName.push({{ ('iTopUpdate:UI:SetupMessage:' ~ sStep)|dict_s|json_encode|ra var sBackupStep; {% if bDoBackup %} -sBackupStep = "Backup"; +sBackupStep = "backup"; {% endif %} var sFilesArchiveStep; {% if bDoFilesArchive %} -sFilesArchiveStep = "FilesArchive"; +sFilesArchiveStep = "files_archive"; {% endif %} -var aStepsAjaxOperation = ["EnterMaintenance", sBackupStep, sFilesArchiveStep, "CopyFiles", "CheckCompile", "Compile", "UpdateDatabase", "ExitMaintenance", null]; +var aStepsAjaxOperation = ["enter_maintenance", sBackupStep, sFilesArchiveStep, "copy_files", "check_compile", "compile", "update_database", "exit_maintenance", null]; var iNextStep = 0; var oInstallationProgress = $('#installation_progress') @@ -87,7 +89,7 @@ function ExecNextStep() { UpdateProgress(aStepsName[iNextStep], iPercent); iNextStep++; if (sAjaxOperation) { - $.ajax(GetAjaxRequest(sAjaxOperation)) + $.ajax(GetAjaxRequest("core_update_ajax." + sAjaxOperation)) .done(function () { setTimeout(ExecNextStep, 500); }) diff --git a/sources/Application/TwigBase/Controller/Controller.php b/sources/Application/TwigBase/Controller/Controller.php index 8ee65a8c8..7328a3be4 100644 --- a/sources/Application/TwigBase/Controller/Controller.php +++ b/sources/Application/TwigBase/Controller/Controller.php @@ -22,6 +22,7 @@ namespace Combodo\iTop\Application\TwigBase\Controller; use AjaxPage; use ApplicationMenu; use Combodo\iTop\Application\TwigBase\Twig\TwigHelper; +use Combodo\iTop\Controller\AbstractController; use Dict; use ErrorPage; use Exception; @@ -38,7 +39,7 @@ use utils; use WebPage; use ZipArchive; -abstract class Controller +abstract class Controller extends AbstractController { const ENUM_PAGE_TYPE_HTML = 'html'; const ENUM_PAGE_TYPE_BASIC_HTML = 'basic_html'; @@ -85,7 +86,7 @@ abstract class Controller * @param string $sViewPath Path of the twig files * @param string $sModuleName name of the module (or 'core' if not a module) */ - public function __construct($sViewPath, $sModuleName = 'core', $aAdditionalPaths = []) + public function __construct($sViewPath = '', $sModuleName = 'core', $aAdditionalPaths = []) { $this->m_aLinkedScripts = []; $this->m_aLinkedStylesheets = []; @@ -93,14 +94,16 @@ abstract class Controller $this->m_aAjaxTabs = []; $this->m_aDefaultParams = []; $this->m_aBlockParams = []; - $this->SetViewPath($sViewPath, $aAdditionalPaths); $this->SetModuleName($sModuleName); - if ($sModuleName != 'core') { - try { - $this->m_aDefaultParams = ['sIndexURL' => utils::GetAbsoluteUrlModulePage($this->m_sModule, 'index.php')]; - } - catch (Exception $e) { - IssueLog::Error($e->getMessage()); + if (strlen($sViewPath) > 0) { + $this->SetViewPath($sViewPath, $aAdditionalPaths); + if ($sModuleName != 'core') { + try { + $this->m_aDefaultParams = ['sIndexURL' => utils::GetAbsoluteUrlModulePage($this->m_sModule, 'index.php')]; + } + catch (Exception $e) { + IssueLog::Error($e->getMessage()); + } } } } @@ -240,7 +243,7 @@ abstract class Controller /** * @throws \Exception */ - private function CheckAccess() + protected function CheckAccess() { if ($this->m_bCheckDemoMode && MetaModel::GetConfig()->Get('demo_mode')) {