MDL-29317 gradeimport_csv: Case-insensitive query for email and username
Query using the following fields for \gradeimport_csv_load_data::check_user_exists() should be done in a case-insensitive manner: * email - As agreed in MDL-29315 * username - Although usernames can only be in lowercase during registration, usernames are being handled in a case-insensitive fashion when logging in. It makes sense to make check_user_exists() consistent with this behaviour.
This commit is contained in:
@@ -225,8 +225,23 @@ class gradeimport_csv_load_data {
|
||||
$errorkey = false;
|
||||
// The user may use the incorrect field to match the user. This could result in an exception.
|
||||
try {
|
||||
$field = $userfields['field'];
|
||||
// Fields that can be queried in a case-insensitive manner.
|
||||
$caseinsensitivefields = [
|
||||
'email',
|
||||
'username',
|
||||
];
|
||||
// Build query predicate.
|
||||
if (in_array($field, $caseinsensitivefields)) {
|
||||
// Case-insensitive.
|
||||
$select = $DB->sql_equal($field, ':' . $field, false);
|
||||
} else {
|
||||
// Exact-value.
|
||||
$select = "{$field} = :{$field}";
|
||||
}
|
||||
|
||||
// Make sure the record exists and that there's only one matching record found.
|
||||
$user = $DB->get_record('user', array($userfields['field'] => $value), '*', MUST_EXIST);
|
||||
$user = $DB->get_record_select('user', $select, array($userfields['field'] => $value), '*', MUST_EXIST);
|
||||
} catch (dml_missing_record_exception $missingex) {
|
||||
$errorkey = 'usermappingerror';
|
||||
} catch (dml_multiple_records_exception $multiex) {
|
||||
|
||||
Reference in New Issue
Block a user