$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;
}
/**
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.
*
);
}
+ /**
+ * 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.
*
);
}
+ /**
+ * 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 $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.
*/