Skip to content

Commit

Permalink
MDL-9431 & MDL-10624 - we're not removing some tracking records from the
Browse files Browse the repository at this point in the history
database when we unassign roles - remove forum_subscriptions & user_lastaccess
  • Loading branch information
poltawski committed Aug 6, 2007
1 parent 4adbf6c commit 19ec0f2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2316,15 +2316,29 @@ function role_unassign($roleid=0, $userid=0, $groupid=0, $contextid=0, $enrol=NU

/// now handle metacourse role unassigment and removing from goups if in course context
if (!empty($context) and $context->contextlevel == CONTEXT_COURSE) {
// remove from groups when user has no capability to view course

// cleanup leftover course groups/subscriptions etc when user has
// no capability to view course
// this may be slow, but this is the proper way of doing it
if (!has_capability('moodle/course:view', $context, $ra->userid)) {
// remove from groups
if ($groups = get_groups($context->instanceid, $ra->userid)) {
foreach ($groups as $group) {
delete_records('groups_members', 'groupid', $group->id, 'userid', $ra->userid);
}
}

// remove any forum subscriptions which may be present
if ($forums = get_records('forum', 'course', $context->instanceid)) {
foreach ($forums as $forum) {
delete_records('forum_subscriptions', 'forum', $forum->id, 'userid', $userid);
}
}

// delete lastaccess records
delete_records('user_lastaccess', 'userid', $ra->userid, 'courseid', $context->instanceid);
}

//unassign roles in metacourses if needed
if ($parents = get_records('course_meta', 'child_course', $context->instanceid)) {
foreach ($parents as $parent) {
Expand Down

0 comments on commit 19ec0f2

Please sign in to comment.