Commit d2aa3e05 authored by Juan Leyva's avatar Juan Leyva
Browse files

MDL-69283 webservice: New external setting for forcing timezone

parent 5486b031
...@@ -1217,6 +1217,9 @@ class external_settings { ...@@ -1217,6 +1217,9 @@ class external_settings {
/** @var string The session lang */ /** @var string The session lang */
private $lang = ''; private $lang = '';
/** @var string The timezone to use during this WS request */
private $timezone = '';
/** /**
* Constructor - protected - can not be instanciated * Constructor - protected - can not be instanciated
*/ */
...@@ -1337,6 +1340,24 @@ class external_settings { ...@@ -1337,6 +1340,24 @@ class external_settings {
public function get_lang() { public function get_lang() {
return $this->lang; return $this->lang;
} }
/**
* Set timezone
*
* @param string $timezone
*/
public function set_timezone($timezone) {
$this->timezone = $timezone;
}
/**
* Get timezone
*
* @return string
*/
public function get_timezone() {
return $this->timezone;
}
} }
/** /**
......
...@@ -1160,6 +1160,7 @@ abstract class webservice_server implements webservice_server_interface { ...@@ -1160,6 +1160,7 @@ abstract class webservice_server implements webservice_server_interface {
'fileurl' => array('default' => true, 'type' => PARAM_BOOL), 'fileurl' => array('default' => true, 'type' => PARAM_BOOL),
'filter' => array('default' => false, 'type' => PARAM_BOOL), 'filter' => array('default' => false, 'type' => PARAM_BOOL),
'lang' => array('default' => '', 'type' => PARAM_LANG), 'lang' => array('default' => '', 'type' => PARAM_LANG),
'timezone' => array('default' => '', 'type' => PARAM_TIMEZONE),
); );
// Load the external settings with the web service settings. // Load the external settings with the web service settings.
...@@ -1235,7 +1236,7 @@ abstract class webservice_base_server extends webservice_server { ...@@ -1235,7 +1236,7 @@ abstract class webservice_base_server extends webservice_server {
* @uses die * @uses die
*/ */
public function run() { public function run() {
global $CFG, $SESSION; global $CFG, $USER, $SESSION;
// we will probably need a lot of memory in some functions // we will probably need a lot of memory in some functions
raise_memory_limit(MEMORY_EXTRA); raise_memory_limit(MEMORY_EXTRA);
...@@ -1287,6 +1288,12 @@ abstract class webservice_base_server extends webservice_server { ...@@ -1287,6 +1288,12 @@ abstract class webservice_base_server extends webservice_server {
} }
} }
// Change timezone only in sites where it isn't forced.
$newtimezone = $settings->get_timezone();
if (!empty($newtimezone) && (!isset($CFG->forcetimezone) || $CFG->forcetimezone == 99)) {
$USER->timezone = $newtimezone;
}
// finally, execute the function - any errors are catched by the default exception handler // finally, execute the function - any errors are catched by the default exception handler
$this->execute(); $this->execute();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment