Skip to content

Commit

Permalink
MDL-54030 enrol_lti: confirm tool exists before deleting users
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson authored and andrewnicols committed May 6, 2016
1 parent 8668796 commit a8abd53
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions enrol/lti/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,12 @@ public function delete_instance($instance) {
public function unenrol_user(stdClass $instance, $userid) {
global $DB;

// Get the tool associated with this instance.
$tool = $DB->get_record('enrol_lti_tools', array('enrolid' => $instance->id), 'id', MUST_EXIST);

// Need to remove the user from the users table.
$DB->delete_records('enrol_lti_users', array('userid' => $userid, 'toolid' => $tool->id));
// Get the tool associated with this instance. Note - it may not exist if we have deleted
// the tool. This is fine because we have already cleaned the 'enrol_lti_users' table.
if ($tool = $DB->get_record('enrol_lti_tools', array('enrolid' => $instance->id), 'id')) {
// Need to remove the user from the users table.
$DB->delete_records('enrol_lti_users', array('userid' => $userid, 'toolid' => $tool->id));
}

parent::unenrol_user($instance, $userid);
}
Expand Down

0 comments on commit a8abd53

Please sign in to comment.