Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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   * CLI script to purge caches without asking for confirmation.
  19   *
  20   * @package    core
  21   * @subpackage cli
  22   * @copyright  2011 David Mudrak <david@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  define('CLI_SCRIPT', true);
  27  
  28  require(__DIR__.'/../../config.php');
  29  require_once($CFG->libdir.'/clilib.php');
  30  
  31  $longoptions = [
  32      'help' => false,
  33      'muc' => false,
  34      'theme' => false,
  35      'lang' => false,
  36      'js' => false,
  37      'filter' => false,
  38      'other' => false
  39  ];
  40  list($options, $unrecognized) = cli_get_params($longoptions, ['h' => 'help']);
  41  
  42  if ($unrecognized) {
  43      $unrecognized = implode("\n  ", $unrecognized);
  44      cli_error(get_string('cliunknowoption', 'admin', $unrecognized), 2);
  45  }
  46  
  47  if ($options['help']) {
  48      // The indentation of this string is "wrong" but this is to avoid a extra whitespace in console output.
  49      $help = <<<EOF
  50  Invalidates Moodle internal caches
  51  
  52  Specific caches can be defined (alone or in combination) using arguments. If none are specified,
  53  all caches will be purged.
  54  
  55  Options:
  56  -h, --help            Print out this help
  57      --muc             Purge all MUC caches (includes lang cache)
  58      --theme           Purge theme cache
  59      --lang            Purge language string cache
  60      --js              Purge JavaScript cache
  61      --filter          Purge text filter cache
  62      --other           Purge all file caches and other miscellaneous caches (may include MUC
  63                        if using cachestore_file).
  64  
  65  Example:
  66  \$ sudo -u www-data /usr/bin/php admin/cli/purge_caches.php
  67  
  68  EOF;
  69  
  70      echo $help;
  71      exit(0);
  72  }
  73  
  74  purge_caches(array_filter($options));
  75  
  76  exit(0);