From c808379ef80324f14f08cfb074e28aa53d328c4c Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 1 Feb 2009 16:20:59 +0000 Subject: [PATCH] MDL-10275 moved the rest of environment tests from install.php to admin/index.php; please note that there is no need to update installer lacg packs becuase install.php will not have environment checks anymore soon ;-) --- admin/environment.xml | 27 ++++++++++--- lang/en_utf8/admin.php | 7 ++++ lib/environmentlib.php | 90 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 117 insertions(+), 7 deletions(-) diff --git a/admin/environment.xml b/admin/environment.xml index af566ed1b71..bd51baf351a 100644 --- a/admin/environment.xml +++ b/admin/environment.xml @@ -270,13 +270,30 @@ - - - + - + - + + + + + + + + + + + + + + + + + + + + diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index faffcaaf284..6c53820a2b0 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -378,6 +378,9 @@ $string['enrolmultipleusers'] = 'Enrol the users'; $string['environment'] = 'Environment'; $string['environmenterrortodo'] = 'You must solve all the environmental problems (errors) found above before proceeding to install this Moodle version!'; $string['environmenterrorupgrade'] = 'Warning: you should solve all the environmental problems (errors) found above before proceeding to upgrade this Moodle version! Upgrading without fixing these requirements could cause problems such as data loss. Are you sure you want to continue with the upgrade?'; +$string['environmenmustfixsetting'] = 'PHP setting must be changed.'; +$string['environmenshouldfixsetting'] = 'PHP setting should be changed.'; +$string['environmentsettingok'] = 'Recommended setting detected'; $string['environmentok'] = 'Your server environment meets all minimum requirements.'; $string['environmentrecommendcustomcheck'] = 'if this test fails, it indicates a potential problem'; $string['environmentrecommendinstall'] = 'should be installed and enabled for best results'; @@ -421,6 +424,7 @@ $string['frontpagerestore'] = 'Front Page restore'; $string['frontpageroles'] = 'Front Page roles'; $string['frontpagesettings'] = 'Front Page settings'; $string['fullnamedisplay'] = 'Full Name Format'; +$string['gdrecommended'] = 'GD extension is used for conversion of images, some features such as user progile images will not be available if missing.'; $string['gdversion'] = 'GD version'; $string['generalsettings'] = 'General settings'; $string['geoipfile'] = 'GeoIP City data file'; @@ -723,6 +727,9 @@ $string['sessioncookiedomain'] = 'Cookie domain'; $string['sessioncookiepath'] = 'Cookie path'; $string['sessionhandling'] = 'Session Handling'; $string['sessiontimeout'] = 'Timeout'; +$string['settingsafemode'] = 'Moodle is not fully compatible with safe mode, please ask server administrator to turn it off. Running Moodle under safe mode is not supported, please expect various problems if you do so.'; +$string['settingfileuploads'] = 'File uploading is required for normal operation, please neable it in PHP configuration.'; +$string['settingmemorylimit'] = 'Insufficient memory detected, please set higher memory limit in PHP settings.'; $string['showblocksonmodpages'] = 'Show blocks on module pages'; $string['showdetails'] = 'Show details'; $string['simpletest'] = 'Unit tests'; diff --git a/lib/environmentlib.php b/lib/environmentlib.php index 8998b7b648d..21d734f8f79 100644 --- a/lib/environmentlib.php +++ b/lib/environmentlib.php @@ -50,6 +50,7 @@ define('NO_CUSTOM_CHECK_FOUND', 12); define('CUSTOM_CHECK_FILE_MISSING', 13); define('CUSTOM_CHECK_FUNCTION_MISSING', 14); + define('NO_PHP_SETTINGS_NAME_FOUND', 15); /** * This function will perform the whole check, returning @@ -111,7 +112,6 @@ function check_moodle_environment($version, &$environment_results, $print_table= if ($print_table) { print_moodle_environment($result && $status, $environment_results); } - return ($result && $status); } @@ -194,6 +194,14 @@ function print_moodle_environment($result, $environment_results) { } else { $stringtouse = 'environmentrecommendcustomcheck'; } + } else if ($environment_result->getPart() == 'php_setting') { + if ($status) { + $stringtouse = 'environmentsettingok'; + } else if ($environment_result->getLevel() == 'required') { + $stringtouse = 'environmenmustfixsetting'; + } else { + $stringtouse = 'environmenshouldfixsetting'; + } } else { if ($environment_result->getLevel() == 'required') { $stringtouse = 'environmentrequireinstall'; @@ -455,6 +463,9 @@ function environment_check($version) { $phpext_results = environment_check_php_extensions($version); $results = array_merge($results, $phpext_results); + $phpsetting_results = environment_check_php_settings($version); + $results = array_merge($results, $phpsetting_results); + $custom_results = environment_custom_checks($version); $results = array_merge($results, $custom_results); @@ -520,6 +531,81 @@ function environment_check_php_extensions($version) { return $results; } +/** + * This function will check if php extensions requirements are satisfied + * @param string $version xml version we are going to use to test this server + * @return array array of results encapsulated in one environment_result object + */ +function environment_check_php_settings($version) { + + $results = array(); + +/// Get the enviroment version we need + if (!$data = get_environment_for_version($version)) { + /// Error. No version data found + $result = new environment_results('php_setting'); + $result->setStatus(false); + $result->setErrorCode(NO_VERSION_DATA_FOUND); + return $result; + } + +/// Extract the php_setting part + if (!isset($data['#']['PHP_SETTINGS']['0']['#']['PHP_SETTING'])) { + /// No PHP section found - ignore + return $results; + } +/// Iterate over settings checking them and creating the needed environment_results + foreach($data['#']['PHP_SETTINGS']['0']['#']['PHP_SETTING'] as $setting) { + $result = new environment_results('php_setting'); + /// Check for level + $level = get_level($setting); + $result->setLevel($level); + /// Check for extension name + if (!isset($setting['@']['name'])) { + $result->setStatus(false); + $result->setErrorCode(NO_PHP_SETTINGS_NAME_FOUND); + } else { + $setting_name = $setting['@']['name']; + $setting_value = $setting['@']['value']; + $result->setInfo($setting_name); + + if ($setting_name == 'memory_limit') { + $current = ini_get('memory_limit'); + if ($current == -1) { + $result->setStatus(true); + } else { + $current = get_real_size($current); + $minlimit = get_real_size($setting_value); + if ($current < $minlimit) { + @ini_set('memory_limit', $setting_value); + $current = ini_get('memory_limit'); + $current = get_real_size($current); + } + $result->setStatus($current >= $minlimit); + } + + } else { + $current = ini_get_bool($setting_name); + /// The name exists. Just check if it's an installed extension + if ($current == $setting_value) { + $result->setStatus(true); + } else { + $result->setStatus(false); + } + } + } + + /// Do any actions defined in the XML file. + process_environment_result($setting, $result); + + /// Add the result to the array of results + $results[] = $result; + } + + + return $results; +} + /** * This function will do the custom checks. * @param string $version xml version we are going to use to test this server. @@ -947,7 +1033,7 @@ function process_environment_messages($xml, &$result) { */ class environment_results { - var $part; //which are we checking (database, php, php_extension) + var $part; //which are we checking (database, php, php_extension, php_extension) var $status; //true/false var $error_code; //integer. See constants at the beginning of the file var $level; //required/optional