Merge branch 'MDL-65976-master' of git://github.com/jleyva/moodle into master
[moodle.git] / cache / admin.php
CommitLineData
8139ad13
SH
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 * The administration and management interface for the cache setup and configuration.
19 *
20 * This file is part of Moodle's cache API, affectionately called MUC.
21 *
22 * @package core
23 * @category cache
24 * @copyright 2012 Sam Hemelryk
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 */
27
28require_once('../config.php');
29require_once($CFG->dirroot.'/lib/adminlib.php');
30require_once($CFG->dirroot.'/cache/locallib.php');
31require_once($CFG->dirroot.'/cache/forms.php');
32
5f5776c1
SH
33// The first time the user visits this page we are going to reparse the definitions.
34// Just ensures that everything is up to date.
35// We flag is session so that this only happens once as people are likely to hit
36// this page several times if making changes.
37if (empty($SESSION->cacheadminreparsedefinitions)) {
38 cache_helper::update_definitions();
39 $SESSION->cacheadminreparsedefinitions = true;
40}
41
8139ad13
SH
42$action = optional_param('action', null, PARAM_ALPHA);
43
44admin_externalpage_setup('cacheconfig');
ba9fc5ed 45$adminhelper = cache_factory::instance()->get_administration_display_helper();
8139ad13 46
727c2173 47$notifications = array();
ba9fc5ed
PB
48// Empty array to hold any form information returned from actions.
49$forminfo = [];
8139ad13 50
ba9fc5ed 51// Handle page actions in admin helper class.
8139ad13 52if (!empty($action) && confirm_sesskey()) {
ba9fc5ed 53 $forminfo = $adminhelper->perform_cache_actions($action, $forminfo);
8139ad13
SH
54}
55
ed2de2ec
SH
56// Add cache store warnings to the list of notifications.
57// Obviously as these are warnings they are show as failures.
ba9fc5ed 58foreach (cache_helper::warnings(core_cache\administration_helper::get_store_instance_summaries()) as $warning) {
ed2de2ec
SH
59 $notifications[] = array($warning, false);
60}
727c2173 61
ba9fc5ed
PB
62// Decide on display mode based on returned forminfo.
63$mform = array_key_exists('form', $forminfo) ? $forminfo['form'] : null;
64$title = array_key_exists('title', $forminfo) ? $forminfo['title'] : new lang_string('cacheadmin', 'cache');
65
8139ad13
SH
66$PAGE->set_title($title);
67$PAGE->set_heading($SITE->fullname);
d31fd615 68/* @var core_cache_renderer $renderer */
8139ad13
SH
69$renderer = $PAGE->get_renderer('core_cache');
70
71echo $renderer->header();
72echo $renderer->heading($title);
915140c9 73echo $renderer->notifications($notifications);
8139ad13
SH
74
75if ($mform instanceof moodleform) {
76 $mform->display();
77} else {
ba9fc5ed
PB
78 // Handle main page definition in admin helper class.
79 echo $adminhelper->generate_admin_page($renderer);
8139ad13
SH
80}
81
82echo $renderer->footer();