MDL-36381 cache: fixed bug whereby you couldn't edit store instances

This commit is contained in:
Sam Hemelryk
2012-11-08 10:54:11 +13:00
parent e2c5f38605
commit 81ede547f2
5 changed files with 116 additions and 2 deletions
+10 -2
View File
@@ -784,8 +784,16 @@ abstract class cache_administration_helper extends cache_helper {
$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));
$url = new moodle_url('/cache/admin.php', array('action' => 'editstore', 'plugin' => $plugin, 'store' => $store));
$editform = new $class($url, array('plugin' => $plugin, 'store' => $store, 'locks' => $locks));
// See if the cachestore is going to want to load data for the form.
// If it has a customised add instance form then it is going to want to.
$storeclass = 'cachestore_'.$plugin;
$storedata = $stores[$store];
if (array_key_exists('configuration', $storedata) && method_exists($storeclass, 'config_set_edit_form_data')) {
$storeclass::config_set_edit_form_data($editform, $storedata['configuration']);
}
return $editform;
}
/**
+20
View File
@@ -542,6 +542,26 @@ class cachestore_file implements cache_store, cache_is_key_aware {
return $config;
}
/**
* Allows the cache store to set its data against the edit form before it is shown to the user.
*
* @param moodleform $editform
* @param array $config
*/
public static function config_set_edit_form_data(moodleform $editform, array $config) {
$data = array();
if (!empty($config['path'])) {
$data['path'] = $config['path'];
}
if (!empty($config['autocreate'])) {
$data['autocreate'] = $config['autocreate'];
}
if (!empty($config['prescan'])) {
$data['prescan'] = $config['prescan'];
}
$editform->set_data($data);
}
/**
* Checks to make sure that the path for the file cache exists.
*
+18
View File
@@ -325,6 +325,24 @@ class cachestore_memcache implements cache_store {
);
}
/**
* Allows the cache store to set its data against the edit form before it is shown to the user.
*
* @param moodleform $editform
* @param array $config
*/
public static function config_set_edit_form_data(moodleform $editform, array $config) {
$data = array();
if (!empty($config['servers'])) {
$servers = array();
foreach ($config['servers'] as $server) {
$servers[] = join(":", $server);
}
$data['servers'] = join("\n", $servers);
}
$editform->set_data($data);
}
/**
* Returns true if the user can add an instance of the store plugin.
*
+33
View File
@@ -393,6 +393,39 @@ class cachestore_memcached implements cache_store {
);
}
/**
* Allows the cache store to set its data against the edit form before it is shown to the user.
*
* @param moodleform $editform
* @param array $config
*/
public static function config_set_edit_form_data(moodleform $editform, array $config) {
$data = array();
if (!empty($config['servers'])) {
$servers = array();
foreach ($config['servers'] as $server) {
$servers[] = join(":", $server);
}
$data['servers'] = join("\n", $servers);
}
if (!empty($config['compression'])) {
$data['compression'] = 1;
}
if (!empty($config['serialiser'])) {
$data['serialiser'] = $config['serialiser'];
}
if (!empty($config['prefix'])) {
$data['prefix'] = $config['prefix'];
}
if (!empty($config['hash'])) {
$data['hash'] = $config['hash'];
}
if (!empty($config['bufferwrites'])) {
$data['bufferwrites'] = 1;
}
$editform->set_data($data);
}
/**
* Returns true if the user can add an instance of the store plugin.
*
+35
View File
@@ -424,6 +424,41 @@ class cachestore_mongodb implements cache_store {
return $return;
}
/**
* Allows the cache store to set its data against the edit form before it is shown to the user.
*
* @param moodleform $editform
* @param array $config
*/
public static function config_set_edit_form_data(moodleform $editform, array $config) {
$data = array();
if (!empty($config['server'])) {
$data['server'] = $config['server'];
}
if (!empty($config['database'])) {
$data['database'] = $config['database'];
}
if (!empty($config['extendedmode'])) {
$data['extendedmode'] = 1;
}
if (!empty($config['username'])) {
$data['username'] = $config['username'];
}
if (!empty($config['password'])) {
$data['password'] = $config['password'];
}
if (!empty($config['replicaset'])) {
$data['replicaset'] = $config['replicaset'];
}
if (!empty($config['usesafe'])) {
$data['usesafe'] = 1;
if ($data['usesafe'] !== true) {
$data['usesafevalue'] = (int)$data['usesafe'];
}
}
$editform->set_data($data);
}
/**
* Performs any necessary clean up when the store instance is being deleted.
*/