From c2e31de263212ee76e0eea4403e95edf746e3102 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Mon, 16 Nov 2020 17:39:24 +0100 Subject: [PATCH] :art: SetupUtils fix methods modifiers + formatting --- setup/setuputils.class.inc.php | 81 +++++++++++++++++----------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php index 39e5696dc..04124a2bb 100644 --- a/setup/setuputils.class.inc.php +++ b/setup/setuputils.class.inc.php @@ -1321,17 +1321,16 @@ EOF * * @return boolean false if DB doesn't meet the minimum version requirement */ - static private function CheckDbServerVersion(&$aResult, $oDBSource) + private static function CheckDbServerVersion(&$aResult, $oDBSource) { - $sDBVendor= $oDBSource->GetDBVendor(); + $sDBVendor = $oDBSource->GetDBVendor(); $sDBVersion = $oDBSource->GetDBVersion(); if ( !empty(self::MYSQL_NOT_VALIDATED_VERSION) && ($sDBVendor === CMDBSource::ENUM_DB_VENDOR_MYSQL) && version_compare($sDBVersion, self::MYSQL_NOT_VALIDATED_VERSION, '>=') - ) - { + ) { $aResult['checks'][] = new CheckResult(CheckResult::ERROR, "Error: Current MySQL version is $sDBVersion. iTop doesn't yet support MySQL ".self::MYSQL_NOT_VALIDATED_VERSION." and above."); @@ -1381,17 +1380,18 @@ EOF * @return string * @throws \MySQLException */ - static public function GetMySQLVersion( + public static function GetMySQLVersion( $sDBServer, $sDBUser, $sDBPwd, $bTlsEnabled = false, $sTlsCa = null ) { $oDBSource = new CMDBSource; $oDBSource->Init($sDBServer, $sDBUser, $sDBPwd, '', $bTlsEnabled, $sTlsCa); $sDBVersion = $oDBSource->GetDBVersion(); + return $sDBVersion; } - static public function AsyncCheckDB($oPage, $aParameters) + public static function AsyncCheckDB($oPage, $aParameters) { $sDBServer = $aParameters['db_server']; $sDBUser = $aParameters['db_user']; @@ -1399,8 +1399,7 @@ EOF $sDBName = $aParameters['db_name']; $bIsWindows = (array_key_exists('WINDIR', $_SERVER) || array_key_exists('windir', $_SERVER)); - if ($bIsWindows && (preg_match('@([%!"])@',$sDBPwd) > 0)) - { + if ($bIsWindows && (preg_match('@([%!"])@', $sDBPwd) > 0)) { // Unsupported Password, warn the user $oPage->add_ready_script( << description */ - static public function GetAvailableLanguages($sDir) + public static function GetAvailableLanguages($sDir) { require_once(APPROOT.'/core/coreexception.class.inc.php'); require_once(APPROOT.'/core/dict.class.inc.php'); $aFiles = scandir($sDir); - foreach($aFiles as $sFile) - { - if ($sFile == '.' || $sFile == '..' || $sFile == '.svn' || $sFile == '.git') - { + foreach ($aFiles as $sFile) { + if ($sFile == '.' || $sFile == '..' || $sFile == '.svn' || $sFile == '.git') { // Skip continue; } $sFilePath = $sDir.'/'.$sFile; - if (is_file($sFilePath) && preg_match('/^.*dict.*\.php$/i', $sFilePath, $aMatches)) - { + if (is_file($sFilePath) && preg_match('/^.*dict.*\.php$/i', $sFilePath, $aMatches)) { require_once($sFilePath); } } @@ -1538,15 +1536,15 @@ JS return Dict::GetLanguages(); } - static public function GetLanguageSelect($sSourceDir, $sInputName, $sDefaultLanguageCode) + public static function GetLanguageSelect($sSourceDir, $sInputName, $sDefaultLanguageCode) { $sHtml = ''; @@ -1919,40 +1917,42 @@ JS public static function GetCompatibleDataModelDir($sInstalledVersion) { - if (preg_match('/^([0-9]+)\./', $sInstalledVersion, $aMatches)) - { + if (preg_match('/^([0-9]+)\./', $sInstalledVersion, $aMatches)) { $sMajorVersion = $aMatches[1]; $sDir = APPROOT.'datamodels/'.$sMajorVersion.'.x/'; - if (is_dir($sDir)) - { + if (is_dir($sDir)) { return $sDir; } } + return false; } - static public function GetDataModelVersion($sDatamodelDir) + public static function GetDataModelVersion($sDatamodelDir) { $sVersionFile = $sDatamodelDir.'version.xml'; - if (file_exists($sVersionFile)) - { + if (file_exists($sVersionFile)) { $oParams = new XMLParameters($sVersionFile); + return $oParams->Get('version'); } + return false; } /** * Returns an array of xml nodes describing the licences. - * @param $sEnv string|null Execution environment. If present loads licenses only for installed modules else loads all licenses available. + * + * @param $sEnv string|null Execution environment. If present loads licenses only for installed modules else loads all licenses + * available. + * * @return array Licenses list. */ - static public function GetLicenses($sEnv = null) + public static function GetLicenses($sEnv = null) { $aLicenses = array(); $aLicenceFiles = glob(APPROOT.'setup/licenses/*.xml'); - if (empty($sEnv)) - { + if (empty($sEnv)) { $aLicenceFiles = array_merge($aLicenceFiles, glob(APPROOT.'datamodels/*/*/license.*.xml')); $aLicenceFiles = array_merge($aLicenceFiles, glob(APPROOT.'extensions/*/license.*.xml')); $aLicenceFiles = array_merge($aLicenceFiles, glob(APPROOT.'data/*-modules/*/license.*.xml')); @@ -1966,19 +1966,19 @@ JS $oXml = simplexml_load_file($sFile); if (!empty($oXml->license)) { - foreach ($oXml->license as $oLicense) - { + foreach ($oXml->license as $oLicense) { $aLicenses[(string)$oLicense->product] = $oLicense; } } } + return $aLicenses; } /** * @return string path to the log file where the create and/or alter queries are written */ - static public function GetSetupQueriesFilePath() + public static function GetSetupQueriesFilePath() { return APPROOT.'log/setup-queries-'.strftime('%Y-%m-%d_%H_%M').'.sql'; } @@ -2061,8 +2061,7 @@ JS throw new Exception("Cannot enter $sMode mode, consider stopping the cron temporarily"); } } - } catch (Exception $e) - { + } catch (Exception $e) { // Ignore errors } } @@ -2072,18 +2071,17 @@ JS * * @return string token */ - public final static function CreateSetupToken() + final public static function CreateSetupToken() { - if (!is_dir(APPROOT.'data')) - { + if (!is_dir(APPROOT.'data')) { mkdir(APPROOT.'data'); } - if (!is_dir(APPROOT.'data/setup')) - { + if (!is_dir(APPROOT.'data/setup')) { mkdir(APPROOT.'data/setup'); } $sUID = hash('sha256', rand()); file_put_contents(APPROOT.'data/setup/authent', $sUID); + return $sUID; } @@ -2094,7 +2092,8 @@ JS * * @throws \SecurityException */ - public final static function CheckSetupToken($bRemoveToken = false) { + final public static function CheckSetupToken($bRemoveToken = false) + { $sAuthent = utils::ReadParam('authent', '', false, 'raw_data'); $sTokenFile = APPROOT.'data/setup/authent'; if (!file_exists($sTokenFile) || $sAuthent !== file_get_contents($sTokenFile)) {