Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unexpected error if stored user corrupted #789

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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