/** * Process request from client. * @return void */ public function run() { global $WEBSERVICE_FUNCTION_RUN, $USER, $WEBSERVICE_INSTITUTION, $WEBSERVICE_START; $WEBSERVICE_START = microtime(true); // we will probably need a lot of memory in some functions raise_memory_limit('128M'); // 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(); // finally, execute the function - any errors are catched by the default exception handler $this->execute(); $time_end = microtime(true); $time_taken = $time_end - $WEBSERVICE_START; //log the web service request $log = (object) array('timelogged' => time(), 'userid' => $USER->get('id'), 'externalserviceid' => $this->restricted_serviceid, 'institution' => $WEBSERVICE_INSTITUTION, 'protocol' => 'REST', 'auth' => $this->auth, 'functionname' => $this->functionname, 'timetaken' => "" . $time_taken, 'uri' => $_SERVER['REQUEST_URI'], 'info' => '', 'ip' => getremoteaddr()); insert_record('external_services_logs', $log, 'id', true); // send the results back in correct format $this->send_response(); // session cleanup $this->session_cleanup(); die; }
/** * 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; }
/** * 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; }