MDL-23167 basic "purge all caches" button

This commit is contained in:
Petr Skoda
2010-07-13 15:09:44 +00:00
parent 2288073ac4
commit f87eab7e71
5 changed files with 77 additions and 22 deletions
+1
View File
@@ -378,6 +378,7 @@ if (!empty($CFG->maintenance_enabled)) {
echo $OUTPUT->box(get_string('sitemaintenancewarning2', 'admin', "$CFG->wwwroot/$CFG->admin/settings.php?section=maintenancemode"), 'generalbox adminwarning');
}
echo $OUTPUT->single_button(new moodle_url('/admin/purgecaches.php'), get_string('purgecaches', 'admin'), 'post');
//////////////////////////////////////////////////////////////////////////////////////////////////
//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
+38
View File
@@ -0,0 +1,38 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This script triggers a full purging of system caches,
* this is useful mostly for developers who did not disable the caching.
*
* @package core
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../config.php');
$confirm = optional_param('confirm', 0, PARAM_BOOL);
$PAGE->set_url('/admin/purgecaches.php');
require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
require_sesskey();
purge_all_caches();
redirect(new moodle_url('/admin/index.php'), get_string('purgecachesfinished', 'admin'));
+2
View File
@@ -829,6 +829,8 @@ $string['requiredentrieschanged'] = '<strong>IMPORTANT - PLEASE READ<br/>(This w
$string['requiredtemplate'] = 'Required. You may use template syntax here (%l = lastname, %f = firstname, %u = username). See help for details and examples.';
$string['requiremodintro'] = 'Require activity description';
$string['requires'] = 'Requires';
$string['purgecaches']= 'Purge all caches';
$string['purgecachesfinished']= 'All caches were purged.';
$string['restrictbydefault'] = 'Restrict modules by default';
$string['restrictmodulesfor'] = 'Restrict modules for';
$string['reverseproxy'] = 'Reverse proxy';
+28
View File
@@ -1065,6 +1065,34 @@ function get_users_from_config($value, $capability, $includeadmins = true) {
return $result;
}
/**
* Invalidates browser caches and cached data in temp
* @return void
*/
function purge_all_caches() {
global $CFG;
remove_dir("$CFG->dataroot/rss", true);
reset_text_filters_cache();
js_reset_all_caches();
theme_reset_all_caches();
get_string_manager()->reset_caches();
// purge all other caches: simplepie, etc.
remove_dir($CFG->dataroot.'/cache', true);
// some more diagnostics in case site is misconfigured
if (!check_dir_exists($CFG->dataroot.'/cache', true, true)) {
debugging('Can not create cache directory, please check permissions in dataroot.');
} else if (!is_writeable($CFG->dataroot.'/cache')) {
debugging('Cache directory is not writeable, please verify permissions in dataroot.');
}
clearstatcache();
}
/**
* Get volatile flags
*
+8 -22
View File
@@ -369,7 +369,7 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) {
message_update_providers($component);
upgrade_plugin_mnet_functions($component);
upgrade_reset_caches();
purge_all_caches();
$endcallback($component, true, $verbose);
} else if ($installedversion < $plugin->version) { // upgrade
@@ -398,7 +398,7 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) {
message_update_providers($component);
upgrade_plugin_mnet_functions($component);
upgrade_reset_caches();
purge_all_caches();
$endcallback($component, false, $verbose);
} else if ($installedversion > $plugin->version) {
@@ -497,7 +497,7 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) {
message_update_providers($component);
upgrade_plugin_mnet_functions($component);
upgrade_reset_caches();
purge_all_caches();
$endcallback($component, true, $verbose);
} else if ($currmodule->version < $module->version) {
@@ -525,8 +525,7 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) {
message_update_providers($component);
upgrade_plugin_mnet_functions($component);
upgrade_reset_caches();
remove_dir($CFG->dataroot.'/cache', true); // flush cache
purge_all_caches();
$endcallback($component, false, $verbose);
@@ -658,7 +657,7 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) {
message_update_providers($component);
upgrade_plugin_mnet_functions($component);
upgrade_reset_caches();
purge_all_caches();
$endcallback($component, true, $verbose);
} else if ($currblock->version < $block->version) {
@@ -691,7 +690,7 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) {
message_update_providers($component);
upgrade_plugin_mnet_functions($component);
upgrade_reset_caches();
purge_all_caches();
$endcallback($component, false, $verbose);
} else if ($currblock->version > $block->version) {
@@ -1223,8 +1222,7 @@ function upgrade_core($version, $verbose) {
try {
// Reset caches before any output
upgrade_reset_caches();
remove_dir($CFG->dataroot . '/cache', true); // flush cache
purge_all_caches();
// Upgrade current language pack if we can
if (empty($CFG->skiplangupgrade)) {
@@ -1257,8 +1255,7 @@ function upgrade_core($version, $verbose) {
message_update_providers('moodle');
// Reset caches again, just to be sure
upgrade_reset_caches();
remove_dir($CFG->dataroot . '/cache', true); // flush cache
purge_all_caches();
// Clean up contexts - more and more stuff depends on existence of paths and contexts
cleanup_contexts();
@@ -1313,17 +1310,6 @@ function core_tables_exist() {
}
}
/**
* Invalidates browser caches and cached data in temp
* @return void
*/
function upgrade_reset_caches() {
reset_text_filters_cache();
js_reset_all_caches();
theme_reset_all_caches();
get_string_manager()->reset_caches();
}
/**
* upgrades the mnet rpc definitions for the given component.
* this method doesn't return status, an exception will be thrown in the case of an error