Example #1
0
$renderer = $PAGE->get_renderer('core', 'webservice');
$returnurl = $CFG->wwwroot . "/" . $CFG->admin . "/settings.php?section=externalservices";
$service = $id ? $webservicemanager->get_external_service_by_id($id, MUST_EXIST) : null;
/// DELETE operation
if ($action == 'delete' and confirm_sesskey() and $service and empty($service->component)) {
    //Display confirmation Page
    if (!$confirm) {
        echo $OUTPUT->header();
        echo $renderer->admin_remove_service_confirmation($service);
        echo $OUTPUT->footer();
        die;
    }
    //The user has confirmed the deletion, delete and redirect
    $webservicemanager->delete_service($service->id);
    $params = array('objectid' => $service->id);
    $event = \core\event\webservice_service_deleted::create($params);
    $event->add_record_snapshot('external_services', $service);
    $event->trigger();
    redirect($returnurl);
}
/// EDIT/CREATE/CANCEL operations => at the end redirect to add function page / main service page
$mform = new external_service_form(null, $service);
if ($mform->is_cancelled()) {
    redirect($returnurl);
} else {
    if ($servicedata = $mform->get_data()) {
        $servicedata = (object) $servicedata;
        if (!empty($servicedata->requiredcapability) && $servicedata->requiredcapability == "norequiredcapability") {
            $servicedata->requiredcapability = "";
        }
        //create operation
Example #2
0
 public function test_service_deleted()
 {
     global $CFG, $DB;
     // The Web service API doesn't allow the testing of the events directly by
     // calling some functions which trigger the events, so what we are going here
     // is just checking that the event returns the expected information.
     $sink = $this->redirectEvents();
     // Creating a fake service.
     $service = (object) array('name' => 'Test', 'enabled' => 1, 'requiredcapability' => '', 'restrictedusers' => 0, 'component' => null, 'timecreated' => time(), 'timemodified' => time(), 'shortname' => null, 'downloadfiles' => 0, 'uploadfiles' => 0);
     $service->id = $DB->insert_record('external_services', $service);
     // Trigger the event.
     $params = array('objectid' => $service->id);
     $event = \core\event\webservice_service_deleted::create($params);
     $event->add_record_snapshot('external_services', $service);
     $event->trigger();
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Assert that the event contains the right information.
     $this->assertEquals(context_system::instance(), $event->get_context());
     $this->assertEquals($service->id, $event->objectid);
     $returnurl = $CFG->wwwroot . "/" . $CFG->admin . "/settings.php?section=externalservices";
     $expected = array(SITEID, 'webservice', 'delete', $returnurl, get_string('deleteservice', 'webservice', $service));
     $this->assertEventLegacyLogData($expected, $event);
 }