Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402]

   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.
  13  //
  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/>.
  16  
  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.
  22   *
  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
  27   */
  28  
  29  
  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');
  34  
  35  // Parameters
  36  $action  = optional_param('action', '', PARAM_ALPHANUMEXT);
  37  $version = optional_param('version', '', PARAM_FILE); //
  38  
  39  $extraurlparams = array();
  40  if ($version) {
  41      $extraurlparams['version'] = $version;
  42  }
  43  admin_externalpage_setup('environment', '', $extraurlparams);
  44  
  45  // Handle the 'updatecomponent' action
  46  if ($action == 'updatecomponent' && confirm_sesskey()) {
  47      // Create component installer and execute it
  48      if ($cd = new component_installer('https://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  = 'https://download.moodle.org/environment/environment.zip';
  57                      $a->dest = $CFG->dataroot . '/';
  58                      throw new \moodle_exception($cd->get_error(), 'error', $PAGE->url, $a);
  59                      die();
  60  
  61                  } else {
  62                      throw new \moodle_exception($cd->get_error(), 'error', $PAGE->url);
  63                      die();
  64                  }
  65  
  66              case COMPONENT_UPTODATE:
  67                  redirect($PAGE->url, get_string($cd->get_error(), 'error'));
  68                  die;
  69  
  70              case COMPONENT_INSTALLED:
  71                  redirect($PAGE->url, get_string('componentinstalled', 'admin'));
  72                  die;
  73          }
  74      }
  75  }
  76  
  77  // Get current Moodle version
  78  $current_version = $CFG->release;
  79  
  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;
  90          }
  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;
  95              }
  96          }
  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'));
 101      }
 102  }
 103  
 104  // Get the results of the environment check.
 105  list($envstatus, $environment_results) = check_moodle_environment($version, ENV_SELECT_NEWER);
 106  
 107  // Display the page.
 108  $output = $PAGE->get_renderer('core', 'admin');
 109  echo $output->environment_check_page($versions, $version, $envstatus, $environment_results);