Merge branch 'MDL-38731-25' of git://github.com/danpoltawski/moodle into MOODLE_25_STABLE
[moodle.git] / admin / environment.php
blob5c74f7f6365c920674afbb9784ea4382ddf39e54
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * This file is the admin frontend to execute all the checks available
19 * in the environment.xml file. It includes database, php and
20 * php_extensions. Also, it's possible to update the xml file
21 * from moodle.org be able to check more and more versions.
23 * @package core
24 * @subpackage admin
25 * @copyright 2006 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 require_once('../config.php');
31 require_once($CFG->libdir.'/adminlib.php');
32 require_once($CFG->libdir.'/environmentlib.php');
33 require_once($CFG->libdir.'/componentlib.class.php');
35 // Parameters
36 $action = optional_param('action', '', PARAM_ALPHANUMEXT);
37 $version = optional_param('version', '', PARAM_FILE); //
39 $extraurlparams = array();
40 if ($version) {
41 $extraurlparams['version'] = $version;
43 admin_externalpage_setup('environment', '', $extraurlparams);
45 // Handle the 'updatecomponent' action
46 if ($action == 'updatecomponent' && confirm_sesskey()) {
47 // Create component installer and execute it
48 if ($cd = new component_installer('http://download.moodle.org',
49 'environment',
50 'environment.zip')) {
51 $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
52 switch ($status) {
53 case COMPONENT_ERROR:
54 if ($cd->get_error() == 'remotedownloaderror') {
55 $a = new stdClass();
56 $a->url = 'http://download.moodle.org/environment/environment.zip';
57 $a->dest = $CFG->dataroot . '/';
58 print_error($cd->get_error(), 'error', $PAGE->url, $a);
59 die();
61 } else {
62 print_error($cd->get_error(), 'error', $PAGE->url);
63 die();
66 case COMPONENT_UPTODATE:
67 redirect($PAGE->url, get_string($cd->get_error(), 'error'));
68 die;
70 case COMPONENT_INSTALLED:
71 redirect($PAGE->url, get_string('componentinstalled', 'admin'));
72 die;
77 // Get current Moodle version
78 $current_version = $CFG->release;
80 // Calculate list of versions
81 $versions = array();
82 if ($contents = load_environment_xml()) {
83 if ($env_versions = get_list_of_environment_versions($contents)) {
84 // Set the current version at the beginning
85 $env_version = normalize_version($current_version); //We need this later (for the upwards)
86 $versions[$env_version] = $current_version;
87 // If no version has been previously selected, default to $current_version
88 if (empty($version)) {
89 $version = $env_version;
91 //Iterate over each version, adding bigger than current
92 foreach ($env_versions as $env_version) {
93 if (version_compare(normalize_version($current_version), $env_version, '<')) {
94 $versions[$env_version] = $env_version;
97 // Add 'upwards' to the last element
98 $versions[$env_version] = $env_version.' '.get_string('upwards', 'admin');
99 } else {
100 $versions = array('error' => get_string('error'));
104 // Get the results of the environment check.
105 list($envstatus, $environment_results) = check_moodle_environment($version);
107 // Display the page.
108 $output = $PAGE->get_renderer('core', 'admin');
109 echo $output->environment_check_page($versions, $version, $envstatus, $environment_results);