Skip to content

Commit

Permalink
MDL-25290 cache: renaming to better separate store plugins from lock …
Browse files Browse the repository at this point in the history
…plugins
  • Loading branch information
Sam Hemelryk committed Oct 7, 2012
1 parent 42f2c59 commit 26ce56f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
14 changes: 7 additions & 7 deletions cache/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
admin_externalpage_setup('cacheconfig');
$context = context_system::instance();

$stores = cache_administration_helper::get_store_summaries();
$plugins = cache_administration_helper::get_plugin_summaries();
$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();
Expand Down Expand Up @@ -67,7 +67,7 @@
$config['lock'] = $data->lock;
}
}
$writer->add_plugin_instance($data->name, $data->plugin, $config);
$writer->add_store_instance($data->name, $data->plugin, $config);
redirect($PAGE->url, get_string('addstoresuccess', 'cache', $plugins[$plugin]['name']), 5);
}
break;
Expand All @@ -87,7 +87,7 @@
$config['lock'] = $data->lock;
}
}
$writer->edit_plugin_instance($data->name, $data->plugin, $config);
$writer->edit_store_instance($data->name, $data->plugin, $config);
redirect($PAGE->url, get_string('editstoresuccess', 'cache', $plugins[$plugin]['name']), 5);
}
break;
Expand Down Expand Up @@ -120,7 +120,7 @@
exit;
} else {
$writer = cache_config_writer::instance();
$writer->delete_store($store);
$writer->delete_store_instance($store);
redirect($PAGE->url, get_string('deletestoresuccess', 'cache'), 5);
}
}
Expand Down Expand Up @@ -186,8 +186,8 @@
if ($mform instanceof moodleform) {
$mform->display();
} else {
echo $renderer->plugin_summaries($plugins);
echo $renderer->store_summariers($stores, $plugins);
echo $renderer->store_plugin_summaries($plugins);
echo $renderer->store_instance_summariers($stores, $plugins);
echo $renderer->definition_summaries($definitions, cache_administration_helper::get_definition_actions($context));
echo $renderer->lock_summaries($locks);

Expand Down
2 changes: 1 addition & 1 deletion cache/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function validation($data, $files) {
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_summaries();
$stores = cache_administration_helper::get_store_instance_summaries();
if (array_key_exists($data['name'], $stores)) {
$errors['name'] = get_string('storenamealreadyused', 'cache');
}
Expand Down
20 changes: 10 additions & 10 deletions cache/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function config_save() {
* @return bool
* @throws cache_exception
*/
public function add_plugin_instance($name, $plugin, array $configuration = array()) {
public function add_store_instance($name, $plugin, array $configuration = array()) {
if (array_key_exists($name, $this->configstores)) {
throw new cache_exception('Duplicate name specificed for cache plugin instance. You must provide a unique name.');
}
Expand Down Expand Up @@ -219,7 +219,7 @@ public function set_mode_mappings(array $modemappings) {
* @return bool
* @throws cache_exception
*/
public function edit_plugin_instance($name, $plugin, $configuration) {
public function edit_store_instance($name, $plugin, $configuration) {
if (!array_key_exists($name, $this->configstores)) {
throw new cache_exception('The requested instance does not exist.');
}
Expand Down Expand Up @@ -265,7 +265,7 @@ public function edit_plugin_instance($name, $plugin, $configuration) {
* @return bool
* @throws cache_exception
*/
public function delete_store($name) {
public function delete_store_instance($name) {
if (!array_key_exists($name, $this->configstores)) {
throw new cache_exception('The requested store does not exist.');
}
Expand Down Expand Up @@ -488,7 +488,7 @@ abstract class cache_administration_helper extends cache_helper {
* Returns an array containing all of the information about stores a renderer needs.
* @return array
*/
public static function get_store_summaries() {
public static function get_store_instance_summaries() {
$return = array();
$default = array();
$instance = cache_config::instance();
Expand Down Expand Up @@ -544,7 +544,7 @@ public static function get_store_summaries() {
* Returns an array of information about plugins, everything a renderer needs.
* @return array
*/
public static function get_plugin_summaries() {
public static function get_store_plugin_summaries() {
$return = array();
$plugins = get_plugin_list_with_file('cachestore', 'lib.php', true);
foreach ($plugins as $plugin => $path) {
Expand Down Expand Up @@ -669,7 +669,7 @@ public static function get_definition_actions(context $context) {
* @param array $storedetails
* @return array
*/
public static function get_store_actions($name, array $storedetails) {
public static function get_store_instance_actions($name, array $storedetails) {
$actions = array();
if (has_capability('moodle/site:config', get_system_context())) {
$baseurl = new moodle_url('/cache/admin.php', array('store' => $name, 'sesskey' => sesskey()));
Expand Down Expand Up @@ -699,7 +699,7 @@ public static function get_store_actions($name, array $storedetails) {
* @param array $plugindetails
* @return array
*/
public static function get_plugin_actions($name, array $plugindetails) {
public static function get_store_plugin_actions($name, array $plugindetails) {
$actions = array();
if (has_capability('moodle/site:config', get_system_context())) {
if (!empty($plugindetails['canaddinstance'])) {
Expand Down Expand Up @@ -738,7 +738,7 @@ public static function get_add_store_form($plugin) {
}
}

$locks = self::get_possible_locks_for_plugin($plugindir, $plugin);
$locks = self::get_possible_locks_for_stores($plugindir, $plugin);

$url = new moodle_url('/cache/admin.php', array('action' => 'addstore'));
return new $class($url, array('plugin' => $plugin, 'store' => null, 'locks' => $locks));
Expand Down Expand Up @@ -776,7 +776,7 @@ public static function get_edit_store_form($plugin, $store) {
}
}

$locks = self::get_possible_locks_for_plugin($plugindir, $plugin);
$locks = self::get_possible_locks_for_stores($plugindir, $plugin);

$url = new moodle_url('/cache/admin.php', array('action' => 'editstore'));
return new $class($url, array('plugin' => $plugin, 'store' => $store, 'locks' => $locks));
Expand All @@ -789,7 +789,7 @@ public static function get_edit_store_form($plugin, $store) {
* @param string $plugin
* @return array|false
*/
protected static function get_possible_locks_for_plugin($plugindir, $plugin) {
protected static function get_possible_locks_for_stores($plugindir, $plugin) {
global $CFG; // Needed for includes.
$supportsnativelocking = false;
if (file_exists($plugindir.'/lib.php')) {
Expand Down
8 changes: 4 additions & 4 deletions cache/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class core_cache_renderer extends plugin_renderer_base {
* @param array $plugins
* @return string HTML
*/
public function store_summariers(array $stores, array $plugins) {
public function store_instance_summariers(array $stores, array $plugins) {
$table = new html_table();
$table->head = array(
get_string('storename', 'cache'),
Expand All @@ -69,7 +69,7 @@ public function store_summariers(array $stores, array $plugins) {
$defaultstoreactions = get_string('defaultstoreactions', 'cache');

foreach ($stores as $name => $store) {
$actions = cache_administration_helper::get_store_actions($name, $store);
$actions = cache_administration_helper::get_store_instance_actions($name, $store);
$modes = array();
foreach ($store['modes'] as $mode => $enabled) {
if ($enabled) {
Expand Down Expand Up @@ -127,7 +127,7 @@ public function store_summariers(array $stores, array $plugins) {
* @param array $plugins
* @return string HTML
*/
public function plugin_summaries(array $plugins) {
public function store_plugin_summaries(array $plugins) {
$table = new html_table();
$table->head = array(
get_string('plugin', 'cache'),
Expand All @@ -148,7 +148,7 @@ public function plugin_summaries(array $plugins) {
$table->data = array();

foreach ($plugins as $name => $plugin) {
$actions = cache_administration_helper::get_plugin_actions($name, $plugin);
$actions = cache_administration_helper::get_store_plugin_actions($name, $plugin);

$modes = array();
foreach ($plugin['modes'] as $mode => $enabled) {
Expand Down
32 changes: 16 additions & 16 deletions cache/tests/locallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,26 @@ public function test_add_edit_delete_plugin_instance() {
$this->assertArrayNotHasKey('addplugintest', $config->get_all_stores());
$this->assertArrayNotHasKey('addplugintestwlock', $config->get_all_stores());
// Add a default file instance.
$config->add_plugin_instance('addplugintest', 'file');
$config->add_store_instance('addplugintest', 'file');

cache_factory::reset();
$config = cache_config_writer::instance();
$this->assertArrayHasKey('addplugintest', $config->get_all_stores());

// Add a store with a lock described.
$config->add_plugin_instance('addplugintestwlock', 'file', array('lock' => 'default_file_lock'));
$config->add_store_instance('addplugintestwlock', 'file', array('lock' => 'default_file_lock'));
$this->assertArrayHasKey('addplugintestwlock', $config->get_all_stores());

$config->delete_store('addplugintest');
$config->delete_store_instance('addplugintest');
$this->assertArrayNotHasKey('addplugintest', $config->get_all_stores());
$this->assertArrayHasKey('addplugintestwlock', $config->get_all_stores());

$config->delete_store('addplugintestwlock');
$config->delete_store_instance('addplugintestwlock');
$this->assertArrayNotHasKey('addplugintest', $config->get_all_stores());
$this->assertArrayNotHasKey('addplugintestwlock', $config->get_all_stores());

// Add a default file instance.
$config->add_plugin_instance('storeconfigtest', 'file', array('test' => 'a', 'one' => 'two'));
$config->add_store_instance('storeconfigtest', 'file', array('test' => 'a', 'one' => 'two'));
$stores = $config->get_all_stores();
$this->assertArrayHasKey('storeconfigtest', $stores);
$this->assertArrayHasKey('configuration', $stores['storeconfigtest']);
Expand All @@ -193,7 +193,7 @@ public function test_add_edit_delete_plugin_instance() {
$this->assertEquals('a', $stores['storeconfigtest']['configuration']['test']);
$this->assertEquals('two', $stores['storeconfigtest']['configuration']['one']);

$config->edit_plugin_instance('storeconfigtest', 'file', array('test' => 'b', 'one' => 'three'));
$config->edit_store_instance('storeconfigtest', 'file', array('test' => 'b', 'one' => 'three'));
$stores = $config->get_all_stores();
$this->assertArrayHasKey('storeconfigtest', $stores);
$this->assertArrayHasKey('configuration', $stores['storeconfigtest']);
Expand All @@ -202,25 +202,25 @@ public function test_add_edit_delete_plugin_instance() {
$this->assertEquals('b', $stores['storeconfigtest']['configuration']['test']);
$this->assertEquals('three', $stores['storeconfigtest']['configuration']['one']);

$config->delete_store('storeconfigtest');
$config->delete_store_instance('storeconfigtest');

try {
$config->delete_store('default_application');
$config->delete_store_instance('default_application');
$this->fail('Default store deleted. This should not be possible!');
} catch (Exception $e) {
$this->assertInstanceOf('cache_exception', $e);
}

try {
$config->delete_store('some_crazy_store');
$config->delete_store_instance('some_crazy_store');
$this->fail('You should not be able to delete a store that does not exist.');
} catch (Exception $e) {
$this->assertInstanceOf('cache_exception', $e);
}

try {
// Try with a plugin that does not exist.
$config->add_plugin_instance('storeconfigtest', 'shallowfail', array('test' => 'a', 'one' => 'two'));
$config->add_store_instance('storeconfigtest', 'shallowfail', array('test' => 'a', 'one' => 'two'));
$this->fail('You should not be able to add an instance of a store that does not exist.');
} catch (Exception $e) {
$this->assertInstanceOf('cache_exception', $e);
Expand All @@ -232,7 +232,7 @@ public function test_add_edit_delete_plugin_instance() {
*/
public function test_set_mode_mappings() {
$config = cache_config_writer::instance();
$this->assertTrue($config->add_plugin_instance('setmodetest', 'file'));
$this->assertTrue($config->add_store_instance('setmodetest', 'file'));
$this->assertTrue($config->set_mode_mappings(array(
cache_store::MODE_APPLICATION => array('setmodetest', 'default_application'),
cache_store::MODE_SESSION => array('default_session'),
Expand Down Expand Up @@ -260,7 +260,7 @@ public function test_set_definition_mappings() {
));

$config = cache_config_writer::instance();
$this->assertTrue($config->add_plugin_instance('setdefinitiontest', 'file'));
$this->assertTrue($config->add_store_instance('setdefinitiontest', 'file'));
$this->assertInternalType('array', $config->get_definition_by_id('phpunit/testdefinition'));
$config->set_definition_mappings('phpunit/testdefinition', array('setdefinitiontest', 'default_application'));

Expand Down Expand Up @@ -303,15 +303,15 @@ public function setUp() {
public function test_get_summaries() {
// First the preparation.
$config = cache_config_writer::instance();
$this->assertTrue($config->add_plugin_instance('summariesstore', 'file'));
$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_summaries();
$storesummaries = cache_administration_helper::get_store_instance_summaries();
$this->assertInternalType('array', $storesummaries);
$this->assertArrayHasKey('summariesstore', $storesummaries);
$summary = $storesummaries['summariesstore'];
Expand Down Expand Up @@ -352,7 +352,7 @@ public function test_get_summaries() {
$this->assertInternalType('array', $summary['mappings']);
$this->assertContains('summariesstore', $summary['mappings']);

$pluginsummaries = cache_administration_helper::get_plugin_summaries();
$pluginsummaries = cache_administration_helper::get_store_plugin_summaries();
$this->assertInternalType('array', $pluginsummaries);
$this->assertArrayHasKey('file', $pluginsummaries);
$summary = $pluginsummaries['file'];
Expand Down Expand Up @@ -403,7 +403,7 @@ public function test_get_add_store_form() {
*/
public function test_get_edit_store_form() {
$config = cache_config_writer::instance();
$this->assertTrue($config->add_plugin_instance('summariesstore', 'file'));
$this->assertTrue($config->add_store_instance('summariesstore', 'file'));

$form = cache_administration_helper::get_edit_store_form('file', 'summariesstore');
$this->assertInstanceOf('moodleform', $form);
Expand Down
4 changes: 2 additions & 2 deletions lang/en/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
$string['nativelocking'] = 'This plugin handles its own locking.';
$string['none'] = 'None';
$string['plugin'] = 'Plugin';
$string['pluginsummaries'] = 'Installed cache plugins';
$string['pluginsummaries'] = 'Installed cache stores';
$string['purge'] = 'Purge';
$string['purgestoresuccess'] = 'Successfully purged the requested store.';
$string['requestcount'] = 'Test with {$a} requests';
Expand All @@ -106,7 +106,7 @@
$string['store_default_application'] = 'Default file store for application caches';
$string['store_default_request'] = 'Default static store for request caches';
$string['store_default_session'] = 'Default session store for session caches';
$string['storesummaries'] = 'Configured plugin instances';
$string['storesummaries'] = 'Configured store instances';
$string['supports'] = 'Supports';
$string['supports_multipleidentifiers'] = 'multiple identifiers';
$string['supports_dataguarantee'] = 'data guarantee';
Expand Down

0 comments on commit 26ce56f

Please sign in to comment.