Skip to content

Commit

Permalink
MDL-52781 core_user: fix wrong lang check
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Apr 22, 2016
1 parent c047386 commit aa788b3
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions lib/classes/user.php
Expand Up @@ -332,7 +332,7 @@ protected static function fill_properties_cache() {
$fields['country'] = array('type' => PARAM_ALPHA, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->country,
'choices' => array_merge(array('' => ''), get_string_manager()->get_list_of_countries(true, true)));
$fields['lang'] = array('type' => PARAM_LANG, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->lang,
'choices' => array_merge(array('' => ''), get_string_manager()->get_list_of_languages()));
'choices' => array_merge(array('' => ''), get_string_manager()->get_list_of_translations(false)));
$fields['calendartype'] = array('type' => PARAM_NOTAGS, 'null' => NULL_NOT_ALLOWED, 'default' => $CFG->calendartype,
'choices' => array_merge(array('' => ''), \core_calendar\type_factory::get_list_of_calendar_types()));
$fields['theme'] = array('type' => PARAM_THEME, 'null' => NULL_NOT_ALLOWED,
Expand Down Expand Up @@ -409,8 +409,7 @@ public static function validate($data) {
}
// Check that the value is part of a list of allowed values.
if (!empty(self::$propertiescache[$property]['choices']) &&
!isset(self::$propertiescache[$property]['choices'][$data->$property]) &&
!array_key_exists($data->$property, self::$propertiescache[$property]['choices'])) {
!isset(self::$propertiescache[$property]['choices'][$value])) {
throw new invalid_parameter_exception($value);
}
} catch (invalid_parameter_exception $e) {
Expand Down Expand Up @@ -445,17 +444,7 @@ public static function clean_data($user) {
foreach ($user as $field => $value) {
// Get the property parameter type and do the cleaning.
try {
if (isset(self::$propertiescache[$field]['choices'])) {
if (!array_key_exists($value, self::$propertiescache[$field]['choices'])) {
if (isset(self::$propertiescache[$field]['default'])) {
$user->$field = self::$propertiescache[$field]['default'];
} else {
$user->$field = '';
}
}
} else {
$user->$field = core_user::clean_field($value, $field);
}
$user->$field = core_user::clean_field($value, $field);
} catch (coding_exception $e) {
debugging("The property '$field' could not be cleaned.", DEBUG_DEVELOPER);
}
Expand Down Expand Up @@ -486,6 +475,8 @@ public static function clean_field($data, $field) {
} else {
$data = '';
}
} else {
return $data;
}
} else {
$data = clean_param($data, $type);
Expand Down

0 comments on commit aa788b3

Please sign in to comment.