/** * The definition of the form */ protected final function definition() { global $OUTPUT; $definition = $this->_customdata['definition']; $form = $this->_form; list($component, $area) = explode('/', $definition, 2); list($currentstores, $storeoptions, $defaults) = cache_administration_helper::get_definition_store_options($component, $area); $storedata = cache_administration_helper::get_definition_summaries(); if ($storedata[$definition]['mode'] != cache_store::MODE_REQUEST) { if (isset($storedata[$definition]['canuselocalstore']) && $storedata[$definition]['canuselocalstore']) { $form->addElement('html', $OUTPUT->notification(get_string('localstorenotification', 'cache'), 'notifymessage')); } else { $form->addElement('html', $OUTPUT->notification(get_string('sharedstorenotification', 'cache'), 'notifymessage')); } } $form->addElement('hidden', 'definition', $definition); $form->setType('definition', PARAM_SAFEPATH); $form->addElement('hidden', 'action', 'editdefinitionmapping'); $form->setType('action', PARAM_ALPHA); $requiredoptions = max(3, count($currentstores) + 1); $requiredoptions = min($requiredoptions, count($storeoptions)); $options = array('' => get_string('none')); foreach ($storeoptions as $option => $def) { $options[$option] = $option; if ($def['default']) { $options[$option] .= ' ' . get_string('mappingdefault', 'cache'); } } for ($i = 0; $i < $requiredoptions; $i++) { $title = '...'; if ($i === 0) { $title = get_string('mappingprimary', 'cache'); } else { if ($i === $requiredoptions - 1) { $title = get_string('mappingfinal', 'cache'); } } $form->addElement('select', 'mappings[' . $i . ']', $title, $options); } $i = 0; foreach ($currentstores as $store => $def) { $form->setDefault('mappings[' . $i . ']', $store); $i++; } if (!empty($defaults)) { $form->addElement('static', 'defaults', get_string('defaultmappings', 'cache'), html_writer::tag('strong', join(', ', $defaults))); $form->addHelpButton('defaults', 'defaultmappings', 'cache'); } $this->add_action_buttons(); }
require_once $CFG->dirroot . '/cache/locallib.php'; require_once $CFG->dirroot . '/cache/forms.php'; // The first time the user visits this page we are going to reparse the definitions. // Just ensures that everything is up to date. // We flag is session so that this only happens once as people are likely to hit // this page several times if making changes. if (empty($SESSION->cacheadminreparsedefinitions)) { cache_helper::update_definitions(); $SESSION->cacheadminreparsedefinitions = true; } $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(); $defaultmodestores = cache_administration_helper::get_default_mode_stores(); $locks = cache_administration_helper::get_lock_summaries(); $title = new lang_string('cacheadmin', 'cache'); $mform = null; $notification = null; $notifysuccess = true; if (!empty($action) && confirm_sesskey()) { switch ($action) { case 'rescandefinitions': // Rescan definitions. cache_config_writer::update_definitions(); redirect($PAGE->url); break; case 'addstore': // Add the requested store.
/** * Test the numerous summaries the helper can produce. */ public function test_get_summaries() { // First the preparation. $config = cache_config_writer::instance(); $this->assertTrue($config->add_store_instance('summariesstore', 'file')); $config->set_definition_mappings('core/eventinvalidation', array('summariesstore')); $this->assertTrue($config->set_mode_mappings(array(cache_store::MODE_APPLICATION => array('summariesstore'), cache_store::MODE_SESSION => array('default_session'), cache_store::MODE_REQUEST => array('default_request')))); $storesummaries = cache_administration_helper::get_store_instance_summaries(); $this->assertInternalType('array', $storesummaries); $this->assertArrayHasKey('summariesstore', $storesummaries); $summary = $storesummaries['summariesstore']; // Check the keys $this->assertArrayHasKey('name', $summary); $this->assertArrayHasKey('plugin', $summary); $this->assertArrayHasKey('default', $summary); $this->assertArrayHasKey('isready', $summary); $this->assertArrayHasKey('requirementsmet', $summary); $this->assertArrayHasKey('mappings', $summary); $this->assertArrayHasKey('modes', $summary); $this->assertArrayHasKey('supports', $summary); // Check the important/known values $this->assertEquals('summariesstore', $summary['name']); $this->assertEquals('file', $summary['plugin']); $this->assertEquals(0, $summary['default']); $this->assertEquals(1, $summary['isready']); $this->assertEquals(1, $summary['requirementsmet']); $this->assertEquals(1, $summary['mappings']); $definitionsummaries = cache_administration_helper::get_definition_summaries(); $this->assertInternalType('array', $definitionsummaries); $this->assertArrayHasKey('core/eventinvalidation', $definitionsummaries); $summary = $definitionsummaries['core/eventinvalidation']; // Check the keys $this->assertArrayHasKey('id', $summary); $this->assertArrayHasKey('name', $summary); $this->assertArrayHasKey('mode', $summary); $this->assertArrayHasKey('component', $summary); $this->assertArrayHasKey('area', $summary); $this->assertArrayHasKey('mappings', $summary); // Check the important/known values $this->assertEquals('core/eventinvalidation', $summary['id']); $this->assertInstanceOf('lang_string', $summary['name']); $this->assertEquals(cache_store::MODE_APPLICATION, $summary['mode']); $this->assertEquals('core', $summary['component']); $this->assertEquals('eventinvalidation', $summary['area']); $this->assertInternalType('array', $summary['mappings']); $this->assertContains('summariesstore', $summary['mappings']); $pluginsummaries = cache_administration_helper::get_store_plugin_summaries(); $this->assertInternalType('array', $pluginsummaries); $this->assertArrayHasKey('file', $pluginsummaries); $summary = $pluginsummaries['file']; // Check the keys $this->assertArrayHasKey('name', $summary); $this->assertArrayHasKey('requirementsmet', $summary); $this->assertArrayHasKey('instances', $summary); $this->assertArrayHasKey('modes', $summary); $this->assertArrayHasKey('supports', $summary); $this->assertArrayHasKey('canaddinstance', $summary); $locksummaries = cache_administration_helper::get_lock_summaries(); $this->assertInternalType('array', $locksummaries); $this->assertTrue(count($locksummaries) > 0); $mappings = cache_administration_helper::get_default_mode_stores(); $this->assertInternalType('array', $mappings); $this->assertCount(3, $mappings); $this->assertArrayHasKey(cache_store::MODE_APPLICATION, $mappings); $this->assertInternalType('array', $mappings[cache_store::MODE_APPLICATION]); $this->assertContains('summariesstore', $mappings[cache_store::MODE_APPLICATION]); $potentials = cache_administration_helper::get_definition_store_options('core', 'eventinvalidation'); $this->assertInternalType('array', $potentials); // Currently used, suitable, default $this->assertCount(3, $potentials); $this->assertArrayHasKey('summariesstore', $potentials[0]); $this->assertArrayHasKey('summariesstore', $potentials[1]); $this->assertArrayHasKey('default_application', $potentials[1]); }