MDL-25290 cache: Implemented Cache API aka MUC
This commit is contained in:
Vendored
+183
@@ -0,0 +1,183 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* The administration and management interface for the cache setup and configuration.
|
||||
*
|
||||
* This file is part of Moodle's cache API, affectionately called MUC.
|
||||
*
|
||||
* @package core
|
||||
* @category cache
|
||||
* @copyright 2012 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->dirroot.'/lib/adminlib.php');
|
||||
require_once($CFG->dirroot.'/cache/locallib.php');
|
||||
require_once($CFG->dirroot.'/cache/forms.php');
|
||||
|
||||
$action = optional_param('action', null, PARAM_ALPHA);
|
||||
|
||||
admin_externalpage_setup('cacheconfig');
|
||||
$context = context_system::instance();
|
||||
|
||||
$stores = cache_administration_helper::get_store_summaries();
|
||||
$plugins = cache_administration_helper::get_plugin_summaries();
|
||||
$definitions = cache_administration_helper::get_definition_summaries();
|
||||
$defaultmodestores = cache_administration_helper::get_default_mode_stores();
|
||||
|
||||
$title = new lang_string('cacheadmin', 'cache');
|
||||
$mform = null;
|
||||
$notification = null;
|
||||
$notifysuccess = true;
|
||||
|
||||
if (!empty($action) && confirm_sesskey()) {
|
||||
switch ($action) {
|
||||
case 'rescandefinitions' :
|
||||
cache_config_writer::update_definitions();
|
||||
redirect($PAGE->url);
|
||||
break;
|
||||
case 'addstore' :
|
||||
$plugin = required_param('plugin', PARAM_PLUGIN);
|
||||
$mform = cache_administration_helper::get_add_store_form($plugin);
|
||||
$title = get_string('addstore', 'cache', $plugins[$plugin]['name']);
|
||||
if ($mform->is_cancelled()) {
|
||||
rediect($PAGE->url);
|
||||
} else if ($data = $mform->get_data()) {
|
||||
$config = cache_administration_helper::get_store_configuration_from_data($data);
|
||||
$writer = cache_config_writer::instance();
|
||||
$writer->add_plugin_instance($data->name, $data->plugin, $config);
|
||||
redirect($PAGE->url, get_string('addstoresuccess', 'cache', $plugins[$plugin]['name']), 5);
|
||||
}
|
||||
break;
|
||||
case 'editstore' :
|
||||
$plugin = required_param('plugin', PARAM_PLUGIN);
|
||||
$store = required_param('store', PARAM_TEXT);
|
||||
$mform = cache_administration_helper::get_edit_store_form($plugin, $store);
|
||||
$title = get_string('addstore', 'cache', $plugins[$plugin]['name']);
|
||||
if ($mform->is_cancelled()) {
|
||||
rediect($PAGE->url);
|
||||
} else if ($data = $mform->get_data()) {
|
||||
$config = cache_administration_helper::get_store_configuration_from_data($data);
|
||||
$writer = cache_config_writer::instance();
|
||||
$writer->edit_plugin_instance($data->name, $data->plugin, $config);
|
||||
redirect($PAGE->url, get_string('editstoresuccess', 'cache', $plugins[$plugin]['name']), 5);
|
||||
}
|
||||
break;
|
||||
case 'deletestore' :
|
||||
$store = required_param('store', PARAM_TEXT);
|
||||
$confirm = optional_param('confirm', false, PARAM_BOOL);
|
||||
|
||||
if (!array_key_exists($store, $stores)) {
|
||||
$notifysuccess = false;
|
||||
$notification = get_string('invalidstore');
|
||||
} else if ($stores[$store]['mappings'] > 0) {
|
||||
$notifysuccess = false;
|
||||
$notification = get_string('deletestorehasmappings');
|
||||
}
|
||||
|
||||
if ($notifysuccess) {
|
||||
if (!$confirm) {
|
||||
$title = get_string('confirmstoredeletion', 'cache');
|
||||
$url = new moodle_url($PAGE->url, array('store' => $store, 'confirm' => 1, 'action' => $action, 'sesskey' => sesskey()));
|
||||
$button = new single_button($url, get_string('deletestore', 'cache'));
|
||||
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($title);
|
||||
echo $OUTPUT->confirm(get_string('deletestoreconfirmation', 'cache', $stores[$store]['name']), $button, $PAGE->url);
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
} else {
|
||||
$writer = cache_config_writer::instance();
|
||||
$writer->delete_store($store);
|
||||
redirect($PAGE->url, get_string('deletestoresuccess', 'cache'), 5);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'editdefinitionmapping' :
|
||||
$definition = required_param('definition', PARAM_TEXT);
|
||||
$title = get_string('editdefinitionmappings', 'cache', $definition);
|
||||
$mform = new cache_definition_mappings_form($PAGE->url, array('definition' => $definition));
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($PAGE->url);
|
||||
} else if ($data = $mform->get_data()) {
|
||||
$writer = cache_config_writer::instance();
|
||||
$mappings = array();
|
||||
foreach ($data->mappings as $mapping) {
|
||||
if (!empty($mapping)) {
|
||||
$mappings[] = $mapping;
|
||||
}
|
||||
}
|
||||
$writer->set_definition_mappings($definition, $mappings);
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
break;
|
||||
case 'editmodemappings': // Edit default mode mappings
|
||||
$mform = new cache_mode_mappings_form(null, $stores);
|
||||
$mform->set_data(array(
|
||||
'mode_'.cache_store::MODE_APPLICATION => key($defaultmodestores[cache_store::MODE_APPLICATION]),
|
||||
'mode_'.cache_store::MODE_SESSION => key($defaultmodestores[cache_store::MODE_SESSION]),
|
||||
'mode_'.cache_store::MODE_REQUEST => key($defaultmodestores[cache_store::MODE_REQUEST]),
|
||||
));
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($PAGE->url);
|
||||
} else if ($data = $mform->get_data()) {
|
||||
$mappings = array(
|
||||
cache_store::MODE_APPLICATION => array($data->{'mode_'.cache_store::MODE_APPLICATION}),
|
||||
cache_store::MODE_SESSION => array($data->{'mode_'.cache_store::MODE_SESSION}),
|
||||
cache_store::MODE_REQUEST => array($data->{'mode_'.cache_store::MODE_REQUEST}),
|
||||
);
|
||||
$writer = cache_config_writer::instance();
|
||||
$writer->set_mode_mappings($mappings);
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'purge': // Purge a store cache
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
$renderer = $PAGE->get_renderer('core_cache');
|
||||
|
||||
echo $renderer->header();
|
||||
echo $renderer->heading($title);
|
||||
|
||||
if (!is_null($notification)) {
|
||||
echo $renderer->notification($notification, ($notifysuccess)?'notifysuccess' : 'notifyproblem');
|
||||
}
|
||||
|
||||
if ($mform instanceof moodleform) {
|
||||
$mform->display();
|
||||
} else {
|
||||
echo $renderer->plugin_summaries($plugins);
|
||||
echo $renderer->store_summariers($stores, $plugins);
|
||||
echo $renderer->definition_summaries($definitions, cache_administration_helper::get_definition_actions($context));
|
||||
|
||||
$applicationstore = join(', ', $defaultmodestores[cache_store::MODE_APPLICATION]);
|
||||
$sessionstore = join(', ', $defaultmodestores[cache_store::MODE_SESSION]);
|
||||
$requeststore = join(', ', $defaultmodestores[cache_store::MODE_REQUEST]);
|
||||
$editurl = new moodle_url('/cache/admin.php', array('action' => 'editmodemappings', 'sesskey' => sesskey()));
|
||||
echo $renderer->mode_mappings($applicationstore, $sessionstore, $requeststore, $editurl);
|
||||
}
|
||||
|
||||
echo $renderer->footer();
|
||||
Reference in New Issue
Block a user