diff --git a/cache/locallib.php b/cache/locallib.php index 5b2d8aea2cf..fc927e0d39f 100644 --- a/cache/locallib.php +++ b/cache/locallib.php @@ -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; } /** diff --git a/cache/stores/file/lib.php b/cache/stores/file/lib.php index 3e985122420..3ef346976d6 100644 --- a/cache/stores/file/lib.php +++ b/cache/stores/file/lib.php @@ -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. * diff --git a/cache/stores/memcache/lib.php b/cache/stores/memcache/lib.php index 6d4c33f2b1d..d684403db33 100644 --- a/cache/stores/memcache/lib.php +++ b/cache/stores/memcache/lib.php @@ -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. * diff --git a/cache/stores/memcached/lib.php b/cache/stores/memcached/lib.php index af74c41807d..ed079b1767e 100644 --- a/cache/stores/memcached/lib.php +++ b/cache/stores/memcached/lib.php @@ -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. * diff --git a/cache/stores/mongodb/lib.php b/cache/stores/mongodb/lib.php index 4ffc205ae96..c37e91da3fb 100644 --- a/cache/stores/mongodb/lib.php +++ b/cache/stores/mongodb/lib.php @@ -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. */