Skip to content

Commit

Permalink
MDL-27655 improve purge all caches.
Browse files Browse the repository at this point in the history
If you click the link in the page footer, then it will reliably
redirect you back to the page you were on after purging the caches.

If you go to the purge all caches page in the admin menu, it shows you a
purge button, with no cancel button. Clicking the button purges the
caches and takes you back to the page with the button.
  • Loading branch information
timhunt committed Aug 8, 2013
1 parent 50ff861 commit 2d22f3d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
56 changes: 28 additions & 28 deletions admin/purgecaches.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,37 @@
require_once($CFG->libdir.'/adminlib.php');

$confirm = optional_param('confirm', 0, PARAM_BOOL);
$returnurl = optional_param('returnurl', null, PARAM_LOCALURL);

admin_externalpage_setup('purgecaches');

require_login();
require_capability('moodle/site:config', context_system::instance());

if ($confirm) {
require_sesskey();
// If we have got here as a confirmed aciton, do it.
if ($confirm && isloggedin() && confirm_sesskey()) {
require_capability('moodle/site:config', context_system::instance());

// Valid request. Purge, and redisplay the form so it is easy to purge again
// in the near future.
// Valid request. Purge, and redirect the user back to where they came from.
purge_all_caches();
redirect(new moodle_url('/admin/purgecaches.php'), get_string('purgecachesfinished', 'admin'));

} else {
// Show a confirm form.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('purgecaches', 'admin'));

$url = new moodle_url('/admin/purgecaches.php', array('sesskey'=>sesskey(), 'confirm'=>1));
$button = new single_button($url, get_string('purgecaches','admin'), 'post');

// Cancel button takes them back to the page the were on, if possible,
// otherwise to the site home page.
$return = new moodle_url('/');
if (isset($_SERVER['HTTP_REFERER']) and !empty($_SERVER['HTTP_REFERER'])) {
if ($_SERVER['HTTP_REFERER'] !== "$CFG->wwwroot/$CFG->admin/purgecaches.php") {
$return = $_SERVER['HTTP_REFERER'];
}

if ($returnurl) {
$returnurl = $CFG->wwwroot . $returnurl;
} else {
$returnurl = new moodle_url('/admin/purgecaches.php');
}
redirect($returnurl, get_string('purgecachesfinished', 'admin'));
}

echo $OUTPUT->confirm(get_string('purgecachesconfirm', 'admin'), $button, $return);
echo $OUTPUT->footer();
// Otherwise, show a button to actually purge the caches.
admin_externalpage_setup('purgecaches');

$actionurl = new moodle_url('/admin/purgecaches.php', array('sesskey'=>sesskey(), 'confirm'=>1));
if ($returnurl) {
$actionurl->param('returnurl', $returnurl);
}

echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('purgecaches', 'admin'));

echo $OUTPUT->box_start('generalbox', 'notice');
echo html_writer::tag('p', get_string('purgecachesconfirm', 'admin'));
echo $OUTPUT->single_button($actionurl, get_string('purgecaches', 'admin'), 'post');
echo $OUTPUT->box_end();

echo $OUTPUT->footer();
5 changes: 4 additions & 1 deletion lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,10 @@ public function standard_footer_html() {
$link= '<a title="' . $title . '" href="' . $url . '">' . $txt . '</a>';
$output .= '<div class="profilingfooter">' . $link . '</div>';
}
$output .= '<div class="purgecaches"><a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/purgecaches.php?confirm=1&amp;sesskey='.sesskey().'">'.get_string('purgecaches', 'admin').'</a></div>';
$purgeurl = new moodle_url('/admin/purgecaches.php', array('confirm' => 1,
'sesskey' => sesskey(), 'returnurl' => $this->page->url->out_as_local_url(false)));
$output .= '<div class="purgecaches">' .
html_writer::link($purgeurl, get_string('purgecaches', 'admin')) . '</div>';
}
if (!empty($CFG->debugvalidators)) {
// NOTE: this is not a nice hack, $PAGE->url is not always accurate and $FULLME neither, it is not a bug if it fails. --skodak
Expand Down

0 comments on commit 2d22f3d

Please sign in to comment.