Merge branch 'MDL-29317-master' of git://github.com/junpataleta/moodle
authorDavid Monllaó <davidm@moodle.com>
Mon, 15 Apr 2019 05:41:10 +0000 (07:41 +0200)
committerDavid Monllaó <davidm@moodle.com>
Mon, 15 Apr 2019 05:41:10 +0000 (07:41 +0200)
grade/import/csv/classes/load_data.php
grade/import/csv/tests/load_data_test.php

index d6ad6e9..c1d5067 100644 (file)
@@ -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) {
index 70d41cd..f05e8b5 100644 (file)
@@ -252,6 +252,9 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat
             '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 @@ Bobby,Bunce,,"Moodle HQ","Rock on!",student5@example.com,75.00,,75.00,{exportdat
             '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
             ],