mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 05:25:08 +02:00
MDL-65492 cache admin: make the code easier to understand
This commit is contained in:
parent
f3507273e9
commit
1baf3af3e8
46
cache/admin.php
vendored
46
cache/admin.php
vendored
@ -44,9 +44,9 @@ $action = optional_param('action', null, PARAM_ALPHA);
|
||||
admin_externalpage_setup('cacheconfig');
|
||||
$context = context_system::instance();
|
||||
|
||||
$stores = cache_administration_helper::get_store_instance_summaries();
|
||||
$plugins = cache_administration_helper::get_store_plugin_summaries();
|
||||
$definitions = cache_administration_helper::get_definition_summaries();
|
||||
$storeinstancesummaries = cache_administration_helper::get_store_instance_summaries();
|
||||
$storepluginsummaries = cache_administration_helper::get_store_plugin_summaries();
|
||||
$definitionsummaries = cache_administration_helper::get_definition_summaries();
|
||||
$defaultmodestores = cache_administration_helper::get_default_mode_stores();
|
||||
$locks = cache_administration_helper::get_lock_summaries();
|
||||
|
||||
@ -63,11 +63,11 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
break;
|
||||
case 'addstore' : // Add the requested store.
|
||||
$plugin = required_param('plugin', PARAM_PLUGIN);
|
||||
if (!$plugins[$plugin]['canaddinstance']) {
|
||||
if (!$storepluginsummaries[$plugin]['canaddinstance']) {
|
||||
print_error('ex_unmetstorerequirements', 'cache');
|
||||
}
|
||||
$mform = cache_administration_helper::get_add_store_form($plugin);
|
||||
$title = get_string('addstore', 'cache', $plugins[$plugin]['name']);
|
||||
$title = get_string('addstore', 'cache', $storepluginsummaries[$plugin]['name']);
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($PAGE->url);
|
||||
} else if ($data = $mform->get_data()) {
|
||||
@ -80,14 +80,14 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
}
|
||||
}
|
||||
$writer->add_store_instance($data->name, $data->plugin, $config);
|
||||
redirect($PAGE->url, get_string('addstoresuccess', 'cache', $plugins[$plugin]['name']), 5);
|
||||
redirect($PAGE->url, get_string('addstoresuccess', 'cache', $storepluginsummaries[$plugin]['name']), 5);
|
||||
}
|
||||
break;
|
||||
case 'editstore' : // Edit the requested store.
|
||||
$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']);
|
||||
$title = get_string('addstore', 'cache', $storepluginsummaries[$plugin]['name']);
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($PAGE->url);
|
||||
} else if ($data = $mform->get_data()) {
|
||||
@ -101,17 +101,17 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
}
|
||||
}
|
||||
$writer->edit_store_instance($data->name, $data->plugin, $config);
|
||||
redirect($PAGE->url, get_string('editstoresuccess', 'cache', $plugins[$plugin]['name']), 5);
|
||||
redirect($PAGE->url, get_string('editstoresuccess', 'cache', $storepluginsummaries[$plugin]['name']), 5);
|
||||
}
|
||||
break;
|
||||
case 'deletestore' : // Delete a given store.
|
||||
$store = required_param('store', PARAM_TEXT);
|
||||
$confirm = optional_param('confirm', false, PARAM_BOOL);
|
||||
|
||||
if (!array_key_exists($store, $stores)) {
|
||||
if (!array_key_exists($store, $storeinstancesummaries)) {
|
||||
$notifysuccess = false;
|
||||
$notifications[] = array(get_string('invalidstore', 'cache'), false);
|
||||
} else if ($stores[$store]['mappings'] > 0) {
|
||||
} else if ($storeinstancesummaries[$store]['mappings'] > 0) {
|
||||
$notifysuccess = false;
|
||||
$notifications[] = array(get_string('deletestorehasmappings', 'cache'), false);
|
||||
}
|
||||
@ -127,7 +127,7 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($title);
|
||||
$confirmation = get_string('deletestoreconfirmation', 'cache', $stores[$store]['name']);
|
||||
$confirmation = get_string('deletestoreconfirmation', 'cache', $storeinstancesummaries[$store]['name']);
|
||||
echo $OUTPUT->confirm($confirmation, $button, $PAGE->url);
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
@ -140,7 +140,7 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
break;
|
||||
case 'editdefinitionmapping' : // Edit definition mappings.
|
||||
$definition = required_param('definition', PARAM_SAFEPATH);
|
||||
if (!array_key_exists($definition, $definitions)) {
|
||||
if (!array_key_exists($definition, $definitionsummaries)) {
|
||||
throw new cache_exception('Invalid cache definition requested');
|
||||
}
|
||||
$title = get_string('editdefinitionmappings', 'cache', $definition);
|
||||
@ -161,22 +161,22 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
break;
|
||||
case 'editdefinitionsharing' :
|
||||
$definition = required_param('definition', PARAM_SAFEPATH);
|
||||
if (!array_key_exists($definition, $definitions)) {
|
||||
if (!array_key_exists($definition, $definitionsummaries)) {
|
||||
throw new cache_exception('Invalid cache definition requested');
|
||||
}
|
||||
$title = get_string('editdefinitionsharing', 'cache', $definition);
|
||||
$sharingoptions = $definitions[$definition]['sharingoptions'];
|
||||
$sharingoptions = $definitionsummaries[$definition]['sharingoptions'];
|
||||
$customdata = array('definition' => $definition, 'sharingoptions' => $sharingoptions);
|
||||
$mform = new cache_definition_sharing_form($PAGE->url, $customdata);
|
||||
$mform->set_data(array(
|
||||
'sharing' => $definitions[$definition]['selectedsharingoption'],
|
||||
'userinputsharingkey' => $definitions[$definition]['userinputsharingkey']
|
||||
'sharing' => $definitionsummaries[$definition]['selectedsharingoption'],
|
||||
'userinputsharingkey' => $definitionsummaries[$definition]['userinputsharingkey']
|
||||
));
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($PAGE->url);
|
||||
} else if ($data = $mform->get_data()) {
|
||||
$component = $definitions[$definition]['component'];
|
||||
$area = $definitions[$definition]['area'];
|
||||
$component = $definitionsummaries[$definition]['component'];
|
||||
$area = $definitionsummaries[$definition]['area'];
|
||||
// Purge the stores removing stale data before we alter the sharing option.
|
||||
cache_helper::purge_stores_used_by_definition($component, $area);
|
||||
$writer = cache_config_writer::instance();
|
||||
@ -187,7 +187,7 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
}
|
||||
break;
|
||||
case 'editmodemappings': // Edit default mode mappings.
|
||||
$mform = new cache_mode_mappings_form(null, $stores);
|
||||
$mform = new cache_mode_mappings_form(null, $storeinstancesummaries);
|
||||
$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]),
|
||||
@ -282,7 +282,7 @@ if (!empty($action) && confirm_sesskey()) {
|
||||
|
||||
// Add cache store warnings to the list of notifications.
|
||||
// Obviously as these are warnings they are show as failures.
|
||||
foreach (cache_helper::warnings($stores) as $warning) {
|
||||
foreach (cache_helper::warnings($storeinstancesummaries) as $warning) {
|
||||
$notifications[] = array($warning, false);
|
||||
}
|
||||
|
||||
@ -298,9 +298,9 @@ echo $renderer->notifications($notifications);
|
||||
if ($mform instanceof moodleform) {
|
||||
$mform->display();
|
||||
} else {
|
||||
echo $renderer->store_plugin_summaries($plugins);
|
||||
echo $renderer->store_instance_summariers($stores, $plugins);
|
||||
echo $renderer->definition_summaries($definitions, $context);
|
||||
echo $renderer->store_plugin_summaries($storepluginsummaries);
|
||||
echo $renderer->store_instance_summariers($storeinstancesummaries, $storepluginsummaries);
|
||||
echo $renderer->definition_summaries($definitionsummaries, $context);
|
||||
echo $renderer->lock_summaries($locks);
|
||||
|
||||
$applicationstore = join(', ', $defaultmodestores[cache_store::MODE_APPLICATION]);
|
||||
|
28
cache/locallib.php
vendored
28
cache/locallib.php
vendored
@ -738,7 +738,9 @@ abstract class cache_administration_helper extends cache_helper {
|
||||
|
||||
/**
|
||||
* Returns an array of information about plugins, everything a renderer needs.
|
||||
* @return array
|
||||
*
|
||||
* @return array for each store, an array containing various information about each store.
|
||||
* See the code below for details
|
||||
*/
|
||||
public static function get_store_plugin_summaries() {
|
||||
$return = array();
|
||||
@ -779,7 +781,9 @@ abstract class cache_administration_helper extends cache_helper {
|
||||
|
||||
/**
|
||||
* Returns an array about the definitions. All the information a renderer needs.
|
||||
* @return array
|
||||
*
|
||||
* @return array for each store, an array containing various information about each store.
|
||||
* See the code below for details
|
||||
*/
|
||||
public static function get_definition_summaries() {
|
||||
$factory = cache_factory::instance();
|
||||
@ -845,10 +849,14 @@ abstract class cache_administration_helper extends cache_helper {
|
||||
|
||||
/**
|
||||
* Returns all of the actions that can be performed on a definition.
|
||||
* @param context $context
|
||||
* @return array
|
||||
*
|
||||
* @param context $context the system context.
|
||||
* @param array $definitionsummary information about this cache, from the array returned by
|
||||
* cache_administration_helper::get_definition_summaries(). Currently only 'sharingoptions'
|
||||
* element is used.
|
||||
* @return array of actions. Each action is an array with two elements, 'text' and 'url'.
|
||||
*/
|
||||
public static function get_definition_actions(context $context, array $definition) {
|
||||
public static function get_definition_actions(context $context, array $definitionsummary) {
|
||||
if (has_capability('moodle/site:config', $context)) {
|
||||
$actions = array();
|
||||
// Edit mappings.
|
||||
@ -857,7 +865,7 @@ abstract class cache_administration_helper extends cache_helper {
|
||||
'url' => new moodle_url('/cache/admin.php', array('action' => 'editdefinitionmapping', 'sesskey' => sesskey()))
|
||||
);
|
||||
// Edit sharing.
|
||||
if (count($definition['sharingoptions']) > 1) {
|
||||
if (count($definitionsummary['sharingoptions']) > 1) {
|
||||
$actions[] = array(
|
||||
'text' => get_string('editsharing', 'cache'),
|
||||
'url' => new moodle_url('/cache/admin.php', array('action' => 'editdefinitionsharing', 'sesskey' => sesskey()))
|
||||
@ -877,8 +885,9 @@ abstract class cache_administration_helper extends cache_helper {
|
||||
* Returns all of the actions that can be performed on a store.
|
||||
*
|
||||
* @param string $name The name of the store
|
||||
* @param array $storedetails
|
||||
* @return array
|
||||
* @param array $storedetails information about this store, from the array returned by
|
||||
* cache_administration_helper::get_store_instance_summaries().
|
||||
* @return array of actions. Each action is an array with two elements, 'text' and 'url'.
|
||||
*/
|
||||
public static function get_store_instance_actions($name, array $storedetails) {
|
||||
$actions = array();
|
||||
@ -902,11 +911,12 @@ abstract class cache_administration_helper extends cache_helper {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all of the actions that can be performed on a plugin.
|
||||
*
|
||||
* @param string $name The name of the plugin
|
||||
* @param array $plugindetails information about this store, from the array returned by
|
||||
* cache_administration_helper::get_store_plugin_summaries().
|
||||
* @param array $plugindetails
|
||||
* @return array
|
||||
*/
|
||||
|
66
cache/renderer.php
vendored
66
cache/renderer.php
vendored
@ -40,11 +40,13 @@ class core_cache_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Displays store summaries.
|
||||
*
|
||||
* @param array $stores
|
||||
* @param array $plugins
|
||||
* @param array $storeinstancesummaries information about each store instance,
|
||||
* as returned by cache_administration_helper::get_store_instance_summaries().
|
||||
* @param array $storepluginsummaries information about each store plugin as
|
||||
* returned by cache_administration_helper::get_store_plugin_summaries().
|
||||
* @return string HTML
|
||||
*/
|
||||
public function store_instance_summariers(array $stores, array $plugins) {
|
||||
public function store_instance_summariers(array $storeinstancesummaries, array $storepluginsummaries) {
|
||||
$table = new html_table();
|
||||
$table->head = array(
|
||||
get_string('storename', 'cache'),
|
||||
@ -70,24 +72,24 @@ class core_cache_renderer extends plugin_renderer_base {
|
||||
|
||||
$defaultstoreactions = get_string('defaultstoreactions', 'cache');
|
||||
|
||||
foreach ($stores as $name => $store) {
|
||||
$actions = cache_administration_helper::get_store_instance_actions($name, $store);
|
||||
foreach ($storeinstancesummaries as $name => $storesummary) {
|
||||
$actions = cache_administration_helper::get_store_instance_actions($name, $storesummary);
|
||||
$modes = array();
|
||||
foreach ($store['modes'] as $mode => $enabled) {
|
||||
foreach ($storesummary['modes'] as $mode => $enabled) {
|
||||
if ($enabled) {
|
||||
$modes[] = get_string('mode_'.$mode, 'cache');
|
||||
}
|
||||
}
|
||||
|
||||
$supports = array();
|
||||
foreach ($store['supports'] as $support => $enabled) {
|
||||
foreach ($storesummary['supports'] as $support => $enabled) {
|
||||
if ($enabled) {
|
||||
$supports[] = get_string('supports_'.$support, 'cache');
|
||||
}
|
||||
}
|
||||
|
||||
$info = '';
|
||||
if (!empty($store['default'])) {
|
||||
if (!empty($storesummary['default'])) {
|
||||
$info = $this->output->pix_icon('i/info', $defaultstoreactions, '', array('class' => 'icon'));
|
||||
}
|
||||
$htmlactions = array();
|
||||
@ -95,38 +97,38 @@ class core_cache_renderer extends plugin_renderer_base {
|
||||
$htmlactions[] = $this->output->action_link($action['url'], $action['text']);
|
||||
}
|
||||
|
||||
$isready = $store['isready'] && $store['requirementsmet'];
|
||||
$isready = $storesummary['isready'] && $storesummary['requirementsmet'];
|
||||
$readycell = new html_table_cell;
|
||||
if ($isready) {
|
||||
$readycell->text = $this->output->pix_icon('i/valid', '1');
|
||||
}
|
||||
|
||||
$storename = $store['name'];
|
||||
if (!empty($store['default'])) {
|
||||
$storename = get_string('store_'.$store['name'], 'cache');
|
||||
$storename = $storesummary['name'];
|
||||
if (!empty($storesummary['default'])) {
|
||||
$storename = get_string('store_'.$storesummary['name'], 'cache');
|
||||
}
|
||||
if (!$isready && (int)$store['mappings'] > 0) {
|
||||
if (!$isready && (int)$storesummary['mappings'] > 0) {
|
||||
$readycell->text = $this->output->help_icon('storerequiresattention', 'cache');
|
||||
$readycell->attributes['class'] = 'store-requires-attention';
|
||||
}
|
||||
|
||||
$lock = $store['lock']['name'];
|
||||
if (!empty($store['lock']['default'])) {
|
||||
$lock = get_string($store['lock']['name'], 'cache');
|
||||
$lock = $storesummary['lock']['name'];
|
||||
if (!empty($storesummary['lock']['default'])) {
|
||||
$lock = get_string($storesummary['lock']['name'], 'cache');
|
||||
}
|
||||
|
||||
$row = new html_table_row(array(
|
||||
$storename,
|
||||
get_string('pluginname', 'cachestore_'.$store['plugin']),
|
||||
get_string('pluginname', 'cachestore_'.$storesummary['plugin']),
|
||||
$readycell,
|
||||
$store['mappings'],
|
||||
$storesummary['mappings'],
|
||||
join(', ', $modes),
|
||||
join(', ', $supports),
|
||||
$lock,
|
||||
$info.join(', ', $htmlactions)
|
||||
));
|
||||
$row->attributes['class'] = 'store-'.$name;
|
||||
if ($store['default']) {
|
||||
if ($storesummary['default']) {
|
||||
$row->attributes['class'] .= ' default-store';
|
||||
}
|
||||
$table->data[] = $row;
|
||||
@ -140,12 +142,13 @@ class core_cache_renderer extends plugin_renderer_base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays plugin summaries
|
||||
* Displays plugin summaries.
|
||||
*
|
||||
* @param array $plugins
|
||||
* @param array $storepluginsummaries information about each store plugin as
|
||||
* returned by cache_administration_helper::get_store_plugin_summaries().
|
||||
* @return string HTML
|
||||
*/
|
||||
public function store_plugin_summaries(array $plugins) {
|
||||
public function store_plugin_summaries(array $storepluginsummaries) {
|
||||
$table = new html_table();
|
||||
$table->head = array(
|
||||
get_string('plugin', 'cache'),
|
||||
@ -165,7 +168,7 @@ class core_cache_renderer extends plugin_renderer_base {
|
||||
);
|
||||
$table->data = array();
|
||||
|
||||
foreach ($plugins as $name => $plugin) {
|
||||
foreach ($storepluginsummaries as $name => $plugin) {
|
||||
$actions = cache_administration_helper::get_store_plugin_actions($name, $plugin);
|
||||
|
||||
$modes = array();
|
||||
@ -208,12 +211,15 @@ class core_cache_renderer extends plugin_renderer_base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays definition summaries
|
||||
* Displays definition summaries.
|
||||
*
|
||||
* @param array $definitions
|
||||
* @return string HTML
|
||||
* @param array $definitionsummaries information about each definition, as returned by
|
||||
* cache_administration_helper::get_definition_summaries().
|
||||
* @param context $context the system context.
|
||||
*
|
||||
* @return string HTML.
|
||||
*/
|
||||
public function definition_summaries(array $definitions, context $context) {
|
||||
public function definition_summaries(array $definitionsummaries, context $context) {
|
||||
$table = new html_table();
|
||||
$table->head = array(
|
||||
get_string('definition', 'cache'),
|
||||
@ -235,10 +241,10 @@ class core_cache_renderer extends plugin_renderer_base {
|
||||
);
|
||||
$table->data = array();
|
||||
|
||||
core_collator::asort_array_of_arrays_by_key($definitions, 'name');
|
||||
core_collator::asort_array_of_arrays_by_key($definitionsummaries, 'name');
|
||||
|
||||
$none = new lang_string('none', 'cache');
|
||||
foreach ($definitions as $id => $definition) {
|
||||
foreach ($definitionsummaries as $id => $definition) {
|
||||
$actions = cache_administration_helper::get_definition_actions($context, $definition);
|
||||
$htmlactions = array();
|
||||
foreach ($actions as $action) {
|
||||
@ -400,4 +406,4 @@ class core_cache_renderer extends plugin_renderer_base {
|
||||
$html .= html_writer::end_div();
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user