mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-64958 grade_import: Ensure correct user is being fetched
* We need to ensure that we are checking the correct user account. Since email and idnumber are not unique fields, there's a chance that multiple user records will match when querying for user data using these fields. This might lead to a different user's grades being inadvertently modified during grade import. In such a case, this function needs to return a null userid.
This commit is contained in:
parent
a713ed3ba6
commit
d45f0f0ceb
@ -221,20 +221,23 @@ class gradeimport_csv_load_data {
|
||||
protected function check_user_exists($value, $userfields) {
|
||||
global $DB;
|
||||
|
||||
$usercheckproblem = false;
|
||||
$user = null;
|
||||
$errorkey = false;
|
||||
// The user may use the incorrect field to match the user. This could result in an exception.
|
||||
try {
|
||||
$user = $DB->get_record('user', array($userfields['field'] => $value));
|
||||
} catch (Exception $e) {
|
||||
$usercheckproblem = true;
|
||||
// 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);
|
||||
} catch (dml_missing_record_exception $missingex) {
|
||||
$errorkey = 'usermappingerror';
|
||||
} catch (dml_multiple_records_exception $multiex) {
|
||||
$errorkey = 'usermappingerrormultipleusersfound';
|
||||
}
|
||||
// Field may be fine, but no records were returned.
|
||||
if (!$user || $usercheckproblem) {
|
||||
if ($errorkey) {
|
||||
$usermappingerrorobj = new stdClass();
|
||||
$usermappingerrorobj->field = $userfields['label'];
|
||||
$usermappingerrorobj->value = $value;
|
||||
$this->cleanup_import(get_string('usermappingerror', 'grades', $usermappingerrorobj));
|
||||
$this->cleanup_import(get_string($errorkey, 'grades', $usermappingerrorobj));
|
||||
unset($usermappingerrorobj);
|
||||
return null;
|
||||
}
|
||||
|
@ -834,6 +834,7 @@ $string['usergrade'] = 'User {$a->fullname} ({$a->useridnumber}) on item {$a->gr
|
||||
$string['userid'] = 'User ID';
|
||||
$string['useridnumberwarning'] = 'Users without an ID number are excluded from the export as they cannot be imported';
|
||||
$string['usermappingerror'] = 'User mapping error: Could not find user with {$a->field} of "{$a->value}".';
|
||||
$string['usermappingerrormultipleusersfound'] = 'User mapping error: Multiple users found with {$a->field} of "{$a->value}". Please use a more unique mapping field.';
|
||||
$string['usermappingerrorusernotfound'] = 'User mapping error. Could not find user.';
|
||||
$string['usermappingerrorcurrentgroup'] = 'User is not a member of current group.';
|
||||
$string['userpreferences'] = 'User preferences';
|
||||
|
Loading…
x
Reference in New Issue
Block a user