Permalink
Browse files

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

  • Loading branch information...
1 parent e2c5f38 commit 81ede547f28131aa8a47f1b166365a8b9cc1ce1a Sam Hemelryk committed Nov 7, 2012
Showing with 116 additions and 2 deletions.
  1. +10 −2 cache/locallib.php
  2. +20 −0 cache/stores/file/lib.php
  3. +18 −0 cache/stores/memcache/lib.php
  4. +33 −0 cache/stores/memcached/lib.php
  5. +35 −0 cache/stores/mongodb/lib.php
View
@@ -784,8 +784,16 @@ public static function get_edit_store_form($plugin, $store) {
$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;
}
/**
View
@@ -543,6 +543,26 @@ public static function config_get_configuration_array($data) {
}
/**
+ * 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.
*
* @return bool
@@ -326,6 +326,24 @@ public static function config_get_configuration_array($data) {
}
/**
+ * 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.
*
* @return bool
@@ -394,6 +394,39 @@ public static function config_get_configuration_array($data) {
}
/**
+ * 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.
*
* @return bool
@@ -425,6 +425,41 @@ public static function config_get_configuration_array($data) {
}
/**
+ * 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.
*/
public function cleanup() {

0 comments on commit 81ede54

Please sign in to comment.