mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
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
This commit is contained in:
parent
40859bd5e1
commit
2515adf9ea
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user