Пример #1
0
 /**
  * Test application of the default expiry on a handler.
  */
 public function test_default_hander_expiry_medium()
 {
     global $DB;
     // Set the default expiry of the handler to 3600 seconds.
     $expiration = 3600;
     // Create test data.
     $user = $this->getDataGenerator()->create_user();
     $handler = $this->helper_create_handler('handler_one');
     $record = \core\message\inbound\manager::record_from_handler($handler);
     $record->defaultexpiration = $expiration;
     $DB->update_record('messageinbound_handlers', $record);
     // Generate an address for the handler.
     $dataid = 42;
     $generator = new core_message_inbound_test_helper();
     $generator->set_handler($handler->classname);
     $generator->set_data($dataid);
     $address = $generator->generate($user->id);
     // Check that the datakey created matches the expirytime.
     $key = $DB->get_record('messageinbound_datakeys', array('handler' => $record->id, 'datavalue' => $dataid));
     $this->assertEquals($key->timecreated + $expiration, $key->expires);
 }
Пример #2
0
$classname = optional_param('classname', '', PARAM_RAW);
$pageurl = new moodle_url('/admin/tool/messageinbound/index.php');
if (empty($classname)) {
    $renderer = $PAGE->get_renderer('tool_messageinbound');
    $records = $DB->get_recordset('messageinbound_handlers', null, 'enabled desc', 'classname');
    $instances = array();
    foreach ($records as $record) {
        $instances[] = \core\message\inbound\manager::get_handler($record->classname);
    }
    echo $OUTPUT->header();
    echo $renderer->messageinbound_handlers_table($instances);
    echo $OUTPUT->footer();
} else {
    // Retrieve the handler and its record.
    $handler = \core\message\inbound\manager::get_handler($classname);
    $record = \core\message\inbound\manager::record_from_handler($handler);
    $formurl = new moodle_url($PAGE->url, array('classname' => $classname));
    $mform = new tool_messageinbound_edit_handler_form($formurl, array('handler' => $handler));
    if ($mform->is_cancelled()) {
        redirect($PAGE->url);
    } else {
        if ($data = $mform->get_data()) {
            // Update the record from the form.
            $record->defaultexpiration = (int) $data->defaultexpiration;
            if ($handler->can_change_validateaddress()) {
                $record->validateaddress = !empty($data->validateaddress);
            }
            if ($handler->can_change_enabled()) {
                $record->enabled = !empty($data->enabled);
            }
            $DB->update_record('messageinbound_handlers', $record);