From: poltawski Date: Mon, 6 Aug 2007 18:45:35 +0000 (+0000) Subject: MDL-9431 & MDL-10624 - we're not removing some tracking records from the X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2515adf9ea82cdc30b29ce570bbd4e9b6245ea15;p=moodle.git MDL-9431 & MDL-10624 - we're not removing some tracking records from the database when we unassign roles - remove forum_subscriptions & user_lastaccess Merged from MOODLE_18_STABLE --- diff --git a/lib/accesslib.php b/lib/accesslib.php index c77a339ace..fcc7ec7538 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2342,15 +2342,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) {