/** * Validates the add instance form data * * @param array $data * @param array $files * @return array */ public function validation($data, $files) { $errors = parent::validation($data, $files); if (!array_key_exists('name', $errors)) { if (!preg_match('#^[a-zA-Z0-9\\-_ ]+$#', $data['name'])) { $errors['name'] = get_string('storenameinvalid', 'cache'); } else { if (empty($this->_customdata['store'])) { $stores = cache_administration_helper::get_store_instance_summaries(); if (array_key_exists($data['name'], $stores)) { $errors['name'] = get_string('storenamealreadyused', 'cache'); } } } } if (method_exists($this, 'configuration_validation')) { $newerrors = $this->configuration_validation($data, $files, $errors); // We need to selectiviliy merge here foreach ($newerrors as $element => $error) { if (!array_key_exists($element, $errors)) { $errors[$element] = $error; } } } return $errors; }
/** * Returns an array of warnings from the cache API. * * The warning returned here are for things like conflicting store instance configurations etc. * These get shown on the admin notifications page for example. * * @param array|null $stores An array of stores to get warnings for, or null for all. * @return string[] */ public static function warnings(array $stores = null) { global $CFG; if ($stores === null) { require_once $CFG->dirroot . '/cache/locallib.php'; $stores = cache_administration_helper::get_store_instance_summaries(); } $warnings = array(); foreach ($stores as $store) { if (!empty($store['warnings'])) { $warnings = array_merge($warnings, $store['warnings']); } } return $warnings; }
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'; // 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;
/** * 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]); }