Skip to content

Commit

Permalink
fix unexpected error if stored user corrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Ilin committed Jan 13, 2025
1 parent e70782a commit 77d25a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions lang/en/turnitintooltwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
11 changes: 10 additions & 1 deletion turnitintooltwo_user.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 77d25a9

Please sign in to comment.