Exemplo n.º 1
0
 public function test_function_called()
 {
     // 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();
     $fakelogdata = array(1, 'B', true, null);
     $params = array('other' => array('function' => 'A function'));
     $event = \core\event\webservice_function_called::create($params);
     $event->set_legacy_logdata($fakelogdata);
     $event->trigger();
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     $this->assertEquals(context_system::instance(), $event->get_context());
     $this->assertEquals('A function', $event->other['function']);
     $this->assertEventLegacyLogData($fakelogdata, $event);
 }
Exemplo n.º 2
0
 /**
  * Process request from client.
  *
  * @uses die
  */
 public function run()
 {
     // we will probably need a lot of memory in some functions
     raise_memory_limit(MEMORY_EXTRA);
     // set some longer timeout, this script is not sending any output,
     // this means we need to manually extend the timeout operations
     // that need longer time to finish
     external_api::set_timeout();
     // set up exception handler first, we want to sent them back in correct format that
     // the other system understands
     // we do not need to call the original default handler because this ws handler does everything
     set_exception_handler(array($this, 'exception_handler'));
     // init all properties from the request data
     $this->parse_request();
     // authenticate user, this has to be done after the request parsing
     // this also sets up $USER and $SESSION
     $this->authenticate_user();
     // find all needed function info and make sure user may actually execute the function
     $this->load_function_info();
     // Log the web service request.
     $params = array('other' => array('function' => $this->functionname));
     $event = \core\event\webservice_function_called::create($params);
     $event->set_legacy_logdata(array(SITEID, 'webservice', $this->functionname, '', getremoteaddr(), 0, $this->userid));
     $event->trigger();
     // finally, execute the function - any errors are catched by the default exception handler
     $this->execute();
     // send the results back in correct format
     $this->send_response();
     // session cleanup
     $this->session_cleanup();
     die;
 }
Exemplo n.º 3
0
 /**
  * Runs the SOAP web service.
  *
  * @throws coding_exception
  * @throws moodle_exception
  * @throws webservice_access_exception
  */
 public function run()
 {
     // We will probably need a lot of memory in some functions.
     raise_memory_limit(MEMORY_EXTRA);
     // Set some longer timeout since operations may need longer time to finish.
     external_api::set_timeout();
     // Set up exception handler.
     set_exception_handler(array($this, 'exception_handler'));
     // Init all properties from the request data.
     $this->parse_request();
     // Authenticate user, this has to be done after the request parsing. This also sets up $USER and $SESSION.
     $this->authenticate_user();
     // Make a list of all functions user is allowed to execute.
     $this->init_service_class();
     if ($this->wsdlmode) {
         // Generate the WSDL.
         $this->generate_wsdl();
     }
     // Log the web service request.
     $params = array('other' => array('function' => 'unknown'));
     $event = \core\event\webservice_function_called::create($params);
     $logdataparams = array(SITEID, 'webservice_soap', '', '', $this->serviceclass . ' ' . getremoteaddr(), 0, $this->userid);
     $event->set_legacy_logdata($logdataparams);
     $event->trigger();
     // Handle the SOAP request.
     $this->handle();
     // Session cleanup.
     $this->session_cleanup();
     die;
 }