From 7f2d3ec0c3eac600e42bb9d6d86accef85533258 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Fri, 10 Aug 2007 22:19:40 +0000 Subject: [PATCH] Added new check to be able to compare current and target moodle versions. Executed only on upgrade (not at install). MDL-10722 --- lib/environmentlib.php | 51 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/lib/environmentlib.php b/lib/environmentlib.php index 1428256bc4..1b903f5315 100644 --- a/lib/environmentlib.php +++ b/lib/environmentlib.php @@ -431,11 +431,17 @@ function get_environment_for_version($version) { */ function environment_check($version) { + global $CFG; + /// Normalize the version requested $version = normalize_version($version); $results = array(); //To store all the results +/// Only run the moodle versions checker on upgrade, not on install + if (empty($CFG->running_installer)) { + $results[] = environment_check_moodle($version); + } $results[] = environment_check_unicode($version); $results[] = environment_check_database($version); $results[] = environment_check_php($version); @@ -572,6 +578,47 @@ function environment_custom_checks($version) { return $results; } +/** + * This function will check if Moodle requirements are satisfied + * @param string $version xml version we are going to use to test this server + * @return object results encapsulated in one environment_result object + */ +function environment_check_moodle($version) { + + $result = new environment_results('moodle'); + +/// Get the enviroment version we need + if (!$data = get_environment_for_version($version)) { + /// Error. No version data found + $result->setStatus(false); + $result->setErrorCode(NO_VERSION_DATA_FOUND); + return $result; + } + +/// Extract the moodle part + if (!isset($data['@']['requires'])) { + $needed_version = '1.0'; /// Default to 1.0 if no moodle requires is found + } else { + /// Extract required moodle version + $needed_version = $data['@']['requires']; + } + +/// Now search the version we are using + $current_version = normalize_version(get_config('', 'release')); + +/// And finally compare them, saving results + if (version_compare($current_version, $needed_version, '>=')) { + $result->setStatus(true); + } else { + $result->setStatus(false); + } + $result->setLevel('required'); + $result->setCurrentVersion($current_version); + $result->setNeededVersion($needed_version); + + return $result; +} + /** * This function will check if php requirements are satisfied * @param string $version xml version we are going to use to test this server @@ -648,7 +695,7 @@ function environment_check_unicode($version) { /// Extract the unicode part if (!isset($data['#']['UNICODE'])) { - /// Error. No DATABASE section found + /// Error. No UNICODE section found $result->setStatus(false); $result->setErrorCode(NO_UNICODE_SECTION_FOUND); return $result; @@ -1104,7 +1151,7 @@ function get_level($element) { if (isset($element['@']['level'])) { $level = $element['@']['level']; if (!in_array($level, array('required', 'optional'))) { - debugging('The level of a check in the environment.xml file must be "required" or level="optional".', DEBUG_DEVELOPER); + debugging('The level of a check in the environment.xml file must be "required" or "optional".', DEBUG_DEVELOPER); $level = 'required'; } } else { -- 2.39.5