MDL-69283 webservice: New external setting for forcing timezone
This commit is contained in:
@@ -1217,6 +1217,9 @@ class external_settings {
|
||||
/** @var string The session lang */
|
||||
private $lang = '';
|
||||
|
||||
/** @var string The timezone to use during this WS request */
|
||||
private $timezone = '';
|
||||
|
||||
/**
|
||||
* Constructor - protected - can not be instanciated
|
||||
*/
|
||||
@@ -1337,6 +1340,24 @@ class external_settings {
|
||||
public function get_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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+8
-1
@@ -1160,6 +1160,7 @@ abstract class webservice_server implements webservice_server_interface {
|
||||
'fileurl' => array('default' => true, 'type' => PARAM_BOOL),
|
||||
'filter' => array('default' => false, 'type' => PARAM_BOOL),
|
||||
'lang' => array('default' => '', 'type' => PARAM_LANG),
|
||||
'timezone' => array('default' => '', 'type' => PARAM_TIMEZONE),
|
||||
);
|
||||
|
||||
// Load the external settings with the web service settings.
|
||||
@@ -1235,7 +1236,7 @@ abstract class webservice_base_server extends webservice_server {
|
||||
* @uses die
|
||||
*/
|
||||
public function run() {
|
||||
global $CFG, $SESSION;
|
||||
global $CFG, $USER, $SESSION;
|
||||
|
||||
// we will probably need a lot of memory in some functions
|
||||
raise_memory_limit(MEMORY_EXTRA);
|
||||
@@ -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
|
||||
$this->execute();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user