MDL-60736 tool_mobile: Support session lang in WS

This commit is contained in:
Juan Leyva 2018-01-15 18:09:01 +01:00
parent e236259d97
commit bb14a48851
2 changed files with 47 additions and 5 deletions

View file

@ -1175,6 +1175,9 @@ class external_settings {
/** @var string In which file should the urls be rewritten */ /** @var string In which file should the urls be rewritten */
private $file = 'webservice/pluginfile.php'; private $file = 'webservice/pluginfile.php';
/** @var string The session lang */
private $lang = '';
/** /**
* Constructor - protected - can not be instanciated * Constructor - protected - can not be instanciated
*/ */
@ -1277,6 +1280,24 @@ class external_settings {
public function get_file() { public function get_file() {
return $this->file; return $this->file;
} }
/**
* Set lang
*
* @param string $lang
*/
public function set_lang($lang) {
$this->lang = $lang;
}
/**
* Get lang
*
* @return string
*/
public function get_lang() {
return $this->lang;
}
} }
/** /**

View file

@ -1126,18 +1126,20 @@ abstract class webservice_server implements webservice_server_interface {
// Must be the same XXX key name as the external_settings::set_XXX function. // Must be the same XXX key name as the external_settings::set_XXX function.
// Must be the same XXX ws parameter name as 'moodlewssettingXXX'. // Must be the same XXX ws parameter name as 'moodlewssettingXXX'.
$externalsettings = array( $externalsettings = array(
'raw' => false, 'raw' => array('default' => false, 'type' => PARAM_BOOL),
'fileurl' => true, 'fileurl' => array('default' => true, 'type' => PARAM_BOOL),
'filter' => false); 'filter' => array('default' => false, 'type' => PARAM_BOOL),
'lang' => array('default' => '', 'type' => PARAM_LANG),
);
// Load the external settings with the web service settings. // Load the external settings with the web service settings.
$settings = external_settings::get_instance(); $settings = external_settings::get_instance();
foreach ($externalsettings as $name => $default) { foreach ($externalsettings as $name => $settingdata) {
$wsparamname = 'moodlewssetting' . $name; $wsparamname = 'moodlewssetting' . $name;
// Retrieve and remove the setting parameter from the request. // Retrieve and remove the setting parameter from the request.
$value = optional_param($wsparamname, $default, PARAM_BOOL); $value = optional_param($wsparamname, $settingdata['default'], $settingdata['type']);
unset($_GET[$wsparamname]); unset($_GET[$wsparamname]);
unset($_POST[$wsparamname]); unset($_POST[$wsparamname]);
@ -1203,6 +1205,8 @@ abstract class webservice_base_server extends webservice_server {
* @uses die * @uses die
*/ */
public function run() { public function run() {
global $CFG, $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);
@ -1236,6 +1240,23 @@ abstract class webservice_base_server extends webservice_server {
$event->set_legacy_logdata(array(SITEID, 'webservice', $this->functionname, '' , getremoteaddr() , 0, $this->userid)); $event->set_legacy_logdata(array(SITEID, 'webservice', $this->functionname, '' , getremoteaddr() , 0, $this->userid));
$event->trigger(); $event->trigger();
// Do additional setup stuff.
$settings = external_settings::get_instance();
$sessionlang = $settings->get_lang();
if (!empty($sessionlang)) {
$SESSION->lang = $sessionlang;
}
setup_lang_from_browser();
if (empty($CFG->lang)) {
if (empty($SESSION->lang)) {
$CFG->lang = 'en';
} else {
$CFG->lang = $SESSION->lang;
}
}
// 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();