Merge branch 'MDL-29318-35' of git://github.com/junpataleta/moodle into MOODLE_35_STABLE

This commit is contained in:
Adrian Greeve
2019-04-18 13:51:36 +08:00
5 changed files with 75 additions and 13 deletions
+16 -4
View File
@@ -4694,9 +4694,11 @@ function update_internal_user_password($user, $password, $fasthash = false) {
* @param string $field The user field to be checked for a given value.
* @param string $value The value to match for $field.
* @param int $mnethostid
* @param bool $throwexception If true, it will throw an exception when there's no record found or when there are multiple records
* found. Otherwise, it will just return false.
* @return mixed False, or A {@link $USER} object.
*/
function get_complete_user_data($field, $value, $mnethostid = null) {
function get_complete_user_data($field, $value, $mnethostid = null, $throwexception = false) {
global $CFG, $DB;
if (!$field || !$value) {
@@ -4707,7 +4709,7 @@ function get_complete_user_data($field, $value, $mnethostid = null) {
$field = core_text::strtolower($field);
// List of case insensitive fields.
$caseinsensitivefields = ['username'];
$caseinsensitivefields = ['username', 'email'];
// Build the WHERE clause for an SQL query.
$params = array('fieldval' => $value);
@@ -4734,8 +4736,18 @@ function get_complete_user_data($field, $value, $mnethostid = null) {
}
// Get all the basic user data.
if (! $user = $DB->get_record_select('user', $constraints, $params)) {
return false;
try {
// Make sure that there's only a single record that matches our query.
// For example, when fetching by email, multiple records might match the query as there's no guarantee that email addresses
// are unique. Therefore we can't reliably tell whether the user profile data that we're fetching is the correct one.
$user = $DB->get_record_select('user', $constraints, $params, '*', MUST_EXIST);
} catch (dml_exception $exception) {
if ($throwexception) {
throw $exception;
} else {
// Return false when no records or multiple records were found.
return false;
}
}
// Get various settings and preferences.