/// 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) {