diff --git a/lib/componentlib.class.php b/lib/componentlib.class.php index efddc9dbcba..c10389e5644 100644 --- a/lib/componentlib.class.php +++ b/lib/componentlib.class.php @@ -585,14 +585,13 @@ class lang_installer { /** * Prepare the installer * - * @todo Moodle major version is hardcoded here, should be obtained from version.php or so * @param string|array $langcode a code of the language to install */ public function __construct($langcode = '') { global $CFG; $this->set_queue($langcode); - $this->version = '2.2'; + $this->version = moodle_major_version(true); if (!empty($CFG->langotherroot) and $CFG->langotherroot !== $CFG->dataroot . '/lang') { debugging('The in-built language pack installer does not support alternative location ' . diff --git a/lib/moodlelib.php b/lib/moodlelib.php index fe642a914b6..1f7a154285c 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -8686,6 +8686,42 @@ function moodle_needs_upgrading() { return false; } +/** + * Returns the major version of this site + * + * Moodle version numbers consist of three numbers separated by a dot, for + * example 1.9.11 or 2.0.2. The first two numbers, like 1.9 or 2.0, represent so + * called major version. This function extracts the major version from either + * $CFG->release (default) or eventually from the $release variable defined in + * the main version.php. + * + * @param bool $fromdisk should the version if source code files be used + * @return string|false the major version like '2.3', false if could not be determined + */ +function moodle_major_version($fromdisk = false) { + global $CFG; + + if ($fromdisk) { + $release = null; + require($CFG->dirroot.'/version.php'); + if (empty($release)) { + return false; + } + + } else { + if (empty($CFG->release)) { + return false; + } + $release = $CFG->release; + } + + if (preg_match('/^[0-9]+\.[0-9]+/', $release, $matches)) { + return $matches[0]; + } else { + return false; + } +} + /** * Sets maximum expected time needed for upgrade task. * Please always make sure that upgrade will not run longer!