Beispiel #1
0
 /**
  * The definition of the form
  */
 protected final function definition()
 {
     $definition = $this->_customdata['definition'];
     $form = $this->_form;
     list($component, $area) = explode('/', $definition, 2);
     list($currentstores, $storeoptions, $defaults) = cache_administration_helper::get_definition_store_options($component, $area);
     $form->addElement('hidden', 'definition', $definition);
     $form->addElement('hidden', 'action', 'editdefinitionmapping');
     $requiredoptions = max(3, count($currentstores) + 1);
     $requiredoptions = min($requiredoptions, count($storeoptions));
     $options = array('' => get_string('none'));
     foreach ($storeoptions as $option => $def) {
         $options[$option] = $option;
         if ($def['default']) {
             $options[$option] .= ' ' . get_string('mappingdefault', 'cache');
         }
     }
     for ($i = 0; $i < $requiredoptions; $i++) {
         $title = '...';
         if ($i === 0) {
             $title = get_string('mappingprimary', 'cache');
         } else {
             if ($i === $requiredoptions - 1) {
                 $title = get_string('mappingfinal', 'cache');
             }
         }
         $form->addElement('select', 'mappings[' . $i . ']', $title, $options);
     }
     $i = 0;
     foreach ($currentstores as $store => $def) {
         $form->setDefault('mappings[' . $i . ']', $store);
         $i++;
     }
     if (!empty($defaults)) {
         $form->addElement('static', 'defaults', get_string('defaultmappings', 'cache'), html_writer::tag('strong', join(', ', $defaults)));
         $form->addHelpButton('defaults', 'defaultmappings', 'cache');
     }
     $this->add_action_buttons();
 }
Beispiel #2
0
 /**
  * Returns an array of warnings from the cache API.
  *
  * The warning returned here are for things like conflicting store instance configurations etc.
  * These get shown on the admin notifications page for example.
  *
  * @param array|null $stores An array of stores to get warnings for, or null for all.
  * @return string[]
  */
 public static function warnings(array $stores = null)
 {
     global $CFG;
     if ($stores === null) {
         require_once $CFG->dirroot . '/cache/locallib.php';
         $stores = cache_administration_helper::get_store_instance_summaries();
     }
     $warnings = array();
     foreach ($stores as $store) {
         if (!empty($store['warnings'])) {
             $warnings = array_merge($warnings, $store['warnings']);
         }
     }
     return $warnings;
 }
Beispiel #3
0
     $store = required_param('store', PARAM_TEXT);
     cache_helper::purge_store($store);
     redirect($PAGE->url, get_string('purgestoresuccess', 'cache'), 5);
     break;
 case 'newlockinstance':
     // Adds a new lock instance.
     $lock = required_param('lock', PARAM_ALPHANUMEXT);
     $mform = cache_administration_helper::get_add_lock_form($lock);
     if ($mform->is_cancelled()) {
         redirect($PAGE->url);
     } else {
         if ($data = $mform->get_data()) {
             $factory = cache_factory::instance();
             $config = $factory->create_config_instance(true);
             $name = $data->name;
             $data = cache_administration_helper::get_lock_configuration_from_data($lock, $data);
             $config->add_lock_instance($name, $lock, $data);
             redirect($PAGE->url, get_string('addlocksuccess', 'cache', $name), 5);
         }
     }
     break;
 case 'deletelock':
     // Deletes a lock instance.
     $lock = required_param('lock', PARAM_ALPHANUMEXT);
     $confirm = optional_param('confirm', false, PARAM_BOOL);
     if (!array_key_exists($lock, $locks)) {
         $notifysuccess = false;
         $notification = get_string('invalidlock', 'cache');
     } else {
         if ($locks[$lock]['uses'] > 0) {
             $notifysuccess = false;
Beispiel #4
0
 /**
  * Sets the data for this form.
  *
  * @param array $data
  */
 public function set_data($data)
 {
     if (!isset($data['sharing'])) {
         // Set the default value here. mforms doesn't handle defaults very nicely.
         $data['sharing'] = cache_administration_helper::get_definition_sharing_options(cache_definition::SHARING_DEFAULT);
     }
     parent::set_data($data);
 }
Beispiel #5
0
 /**
  * Test instantiating a form to edit a store instance.
  */
 public function test_get_edit_store_form()
 {
     $config = cache_config_writer::instance();
     $this->assertTrue($config->add_store_instance('summariesstore', 'file'));
     $form = cache_administration_helper::get_edit_store_form('file', 'summariesstore');
     $this->assertInstanceOf('moodleform', $form);
     try {
         $form = cache_administration_helper::get_edit_store_form('somethingstupid', 'moron');
         $this->fail('You should not be able to create an edit form for a store plugin that does not exist.');
     } catch (moodle_exception $e) {
         $this->assertInstanceOf('coding_exception', $e);
     }
     try {
         $form = cache_administration_helper::get_edit_store_form('file', 'blisters');
         $this->fail('You should not be able to create an edit form for a store plugin that does not exist.');
     } catch (moodle_exception $e) {
         $this->assertInstanceOf('coding_exception', $e);
     }
 }
Beispiel #6
0
 /**
  * Display basic information about lock instances.
  *
  * @todo Add some actions so that people can configure lock instances.
  *
  * @param array $locks
  * @return string
  */
 public function lock_summaries(array $locks)
 {
     $table = new html_table();
     $table->colclasses = array('name', 'type', 'default', 'uses', 'actions');
     $table->rowclasses = array('lock_name', 'lock_type', 'lock_default', 'lock_uses', 'lock_actions');
     $table->head = array(get_string('lockname', 'cache'), get_string('locktype', 'cache'), get_string('lockdefault', 'cache'), get_string('lockuses', 'cache'), get_string('actions', 'cache'));
     $table->data = array();
     $tick = $this->output->pix_icon('i/valid', '');
     foreach ($locks as $lock) {
         $actions = array();
         if ($lock['uses'] === 0 && !$lock['default']) {
             $url = new moodle_url('/cache/admin.php', array('lock' => $lock['name'], 'action' => 'deletelock', 'sesskey' => sesskey()));
             $actions[] = html_writer::link($url, get_string('delete', 'cache'));
         }
         $table->data[] = new html_table_row(array(new html_table_cell($lock['name']), new html_table_cell($lock['type']), new html_table_cell($lock['default'] ? $tick : ''), new html_table_cell($lock['uses']), new html_table_cell(join(' ', $actions))));
     }
     $url = new moodle_url('/cache/admin.php', array('action' => 'newlockinstance', 'sesskey' => sesskey()));
     $select = new single_select($url, 'lock', cache_administration_helper::get_addable_lock_options());
     $select->label = get_string('addnewlockinstance', 'cache');
     $html = html_writer::start_tag('div', array('id' => 'core-cache-lock-summary'));
     $html .= $this->output->heading(get_string('locksummary', 'cache'), 3);
     $html .= html_writer::table($table);
     $html .= html_writer::tag('div', $this->output->render($select), array('class' => 'new-instance'));
     $html .= html_writer::end_tag('div');
     return $html;
 }
Beispiel #7
0
 /**
  * Displays plugin summaries
  *
  * @param array $plugins
  * @return string HTML
  */
 public function store_plugin_summaries(array $plugins)
 {
     $table = new html_table();
     $table->head = array(get_string('plugin', 'cache'), get_string('storeready', 'cache'), get_string('stores', 'cache'), get_string('modes', 'cache'), get_string('supports', 'cache'), get_string('actions', 'cache'));
     $table->colclasses = array('plugin', 'storeready', 'stores', 'modes', 'supports', 'actions');
     $table->data = array();
     foreach ($plugins as $name => $plugin) {
         $actions = cache_administration_helper::get_store_plugin_actions($name, $plugin);
         $modes = array();
         foreach ($plugin['modes'] as $mode => $enabled) {
             if ($enabled) {
                 $modes[] = get_string('mode_' . $mode, 'cache');
             }
         }
         $supports = array();
         foreach ($plugin['supports'] as $support => $enabled) {
             if ($enabled) {
                 $supports[] = get_string('supports_' . $support, 'cache');
             }
         }
         $htmlactions = array();
         foreach ($actions as $action) {
             $htmlactions[] = $this->output->action_link($action['url'], $action['text']);
         }
         $row = new html_table_row(array($plugin['name'], $plugin['requirementsmet'] ? $this->output->pix_icon('i/valid', '1') : '', $plugin['instances'], join(', ', $modes), join(', ', $supports), join(', ', $htmlactions)));
         $row->attributes['class'] = 'plugin-' . $name;
         $table->data[] = $row;
     }
     $html = html_writer::start_tag('div', array('id' => 'core-cache-plugin-summaries'));
     $html .= $this->output->heading(get_string('pluginsummaries', 'cache'), 3);
     $html .= html_writer::table($table);
     $html .= html_writer::end_tag('div');
     return $html;
 }
Beispiel #8
0
            break;
        case 'purge':
            // Purge a store cache.
            $store = required_param('store', PARAM_TEXT);
            cache_helper::purge_store($store);
            redirect($PAGE->url, get_string('purgestoresuccess', 'cache'), 5);
            break;
    }
}
$PAGE->set_title($title);
$PAGE->set_heading($SITE->fullname);
$renderer = $PAGE->get_renderer('core_cache');
echo $renderer->header();
echo $renderer->heading($title);
if (!is_null($notification)) {
    echo $renderer->notification($notification, $notifysuccess ? 'notifysuccess' : 'notifyproblem');
}
if ($mform instanceof moodleform) {
    $mform->display();
} else {
    echo $renderer->store_plugin_summaries($plugins);
    echo $renderer->store_instance_summariers($stores, $plugins);
    echo $renderer->definition_summaries($definitions, cache_administration_helper::get_definition_actions($context));
    echo $renderer->lock_summaries($locks);
    $applicationstore = join(', ', $defaultmodestores[cache_store::MODE_APPLICATION]);
    $sessionstore = join(', ', $defaultmodestores[cache_store::MODE_SESSION]);
    $requeststore = join(', ', $defaultmodestores[cache_store::MODE_REQUEST]);
    $editurl = new moodle_url('/cache/admin.php', array('action' => 'editmodemappings', 'sesskey' => sesskey()));
    echo $renderer->mode_mappings($applicationstore, $sessionstore, $requeststore, $editurl);
}
echo $renderer->footer();