Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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 script triggers a full purging of system caches,
  19   * this is useful mostly for developers who did not disable the caching.
  20   *
  21   * @package    core
  22   * @copyright  2010 Petr Skoda {@link http://skodak.org}
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require_once('../config.php');
  27  require_once($CFG->libdir.'/adminlib.php');
  28  
  29  $confirm = optional_param('confirm', 0, PARAM_BOOL);
  30  $returnurl = optional_param('returnurl', '/admin/purgecaches.php', PARAM_LOCALURL);
  31  $returnurl = new moodle_url($returnurl);
  32  
  33  admin_externalpage_setup('purgecaches');
  34  
  35  $form = new core_admin\form\purge_caches(null, ['returnurl' => $returnurl]);
  36  
  37  // If we have got here as a confirmed aciton, do it.
  38  if ($data = $form->get_data()) {
  39  
  40      // Valid request. Purge, and redirect the user back to where they came from.
  41      $selected = $data->purgeselectedoptions;
  42      purge_caches($selected);
  43  
  44      if (isset($data->all)) {
  45          $message = get_string('purgecachesfinished', 'admin');
  46      } else {
  47          $message = get_string('purgeselectedcachesfinished', 'admin');
  48      }
  49  
  50  } else if ($confirm && confirm_sesskey()) {
  51      purge_caches();
  52      $message = get_string('purgecachesfinished', 'admin');
  53  }
  54  
  55  if (isset($message)) {
  56      redirect($returnurl, $message);
  57  }
  58  
  59  // Otherwise, show a form to actually purge the caches.
  60  
  61  echo $OUTPUT->header();
  62  echo $OUTPUT->heading(get_string('purgecachespage', 'admin'));
  63  
  64  echo $OUTPUT->box_start('generalbox', 'notice');
  65  echo html_writer::tag('p', get_string('purgecachesconfirm', 'admin'));
  66  echo $form->render();
  67  echo $OUTPUT->box_end();
  68  
  69  echo $OUTPUT->footer();