Skip to content
Permalink
Browse files
Merge branch 'MDL-29317-master' of git://github.com/junpataleta/moodle
  • Loading branch information
David Monllaó committed Apr 15, 2019
2 parents 0163c6e + 2791334 commit 815c070a2632f6d5bba4c8554c67cce3f44689c3
Showing with 22 additions and 1 deletion.
  1. +16 −1 grade/import/csv/classes/load_data.php
  2. +6 −0 grade/import/csv/tests/load_data_test.php
@@ -225,8 +225,23 @@ protected function check_user_exists($value, $userfields) {
$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) {
@@ -252,6 +252,9 @@ public function check_user_exists_provider() {
'Fetch by email' => [
'email', 's1@example.com', true
],
'Fetch by email, different case' => [
'email', 'S1@EXAMPLE.COM', true
],
'Fetch data using a non-existent email' => [
'email', 's2@example.com', false
],
@@ -267,6 +270,9 @@ public function check_user_exists_provider() {
'Fetch data using a valid username' => [
'username', 's1', true
],
'Fetch data using a valid username, different case' => [
'username', 'S1', true
],
'Fetch data using an invalid username' => [
'username', 's2', false
],

0 comments on commit 815c070

Please sign in to comment.