diff --git a/lang/en/turnitintooltwo.php b/lang/en/turnitintooltwo.php index 17b2d41a..38fab471 100755 --- a/lang/en/turnitintooltwo.php +++ b/lang/en/turnitintooltwo.php @@ -685,3 +685,4 @@ $string['max_marks_warning'] = 'Please be aware that changing the Marks Available after grading may affect the gradebook'; $string['download_button_warning'] = 'A student must be selected for this feature to be available.'; $string['noguests'] = 'Sorry, no guest users are allowed to access this plugin. Please login.'; +$string['usernotfound'] = 'Unable to process user (ID: {$a}). This error might be due to inconsistent course data, corrupted user records, or incorrect user mapping between Moodle and Turnitin. Please contact your Moodle administrator for further investigation.'; \ No newline at end of file diff --git a/turnitintooltwo_user.class.php b/turnitintooltwo_user.class.php index 433b6ad8..840abe6f 100644 --- a/turnitintooltwo_user.class.php +++ b/turnitintooltwo_user.class.php @@ -84,7 +84,16 @@ public static function get_moodle_user_id($tiiuserid) { public function get_moodle_user($userid) { global $DB; - $user = $DB->get_record('user', array('id' => $userid)); + $dbUser = $DB->get_record('user', array('id' => $userid)); + + $user = new TiiUser(); + + if ($dbUser) { + $user = (object) $dbUser; + } else { + \core\notification::add(get_string('usernotfound', 'turnitintooltwo', $userid), \core\output\notification::NOTIFY_ERROR); + return false; + } // Moodle 2.0 replaces email with a hash on deletion, moodle 1.9 deletes the email address check both. if (empty($user->email) || strpos($user->email, '@') === false) {