$notification = null; $notifysuccess = true; if (!empty($action) && confirm_sesskey()) { switch ($action) { case 'rescandefinitions': // Rescan definitions. cache_config_writer::update_definitions(); redirect($PAGE->url); break; case 'addstore': // Add the requested store. $plugin = required_param('plugin', PARAM_PLUGIN); if (!$plugins[$plugin]['canaddinstance']) { print_error('ex_unmetstorerequirements', 'cache'); } $mform = cache_administration_helper::get_add_store_form($plugin); $title = get_string('addstore', 'cache', $plugins[$plugin]['name']); if ($mform->is_cancelled()) { redirect($PAGE->url); } else { if ($data = $mform->get_data()) { $config = cache_administration_helper::get_store_configuration_from_data($data); $writer = cache_config_writer::instance(); unset($config['lock']); foreach ($writer->get_locks() as $lock => $lockconfig) { if ($lock == $data->lock) { $config['lock'] = $data->lock; } } $writer->add_store_instance($data->name, $data->plugin, $config); redirect($PAGE->url, get_string('addstoresuccess', 'cache', $plugins[$plugin]['name']), 5);
/** * Test instantiating an add store form. */ public function test_get_add_store_form() { $form = cache_administration_helper::get_add_store_form('file'); $this->assertInstanceOf('moodleform', $form); try { $form = cache_administration_helper::get_add_store_form('somethingstupid'); $this->fail('You should not be able to create an add form for a store plugin that does not exist.'); } catch (moodle_exception $e) { $this->assertInstanceOf('coding_exception', $e, 'Needs to be: ' . get_class($e) . " ::: " . $e->getMessage()); } }