]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9431 & MDL-10624 - we're not removing some tracking records from the
authorpoltawski <poltawski>
Mon, 6 Aug 2007 18:45:35 +0000 (18:45 +0000)
committerpoltawski <poltawski>
Mon, 6 Aug 2007 18:45:35 +0000 (18:45 +0000)
database when we unassign roles - remove forum_subscriptions & user_lastaccess

Merged from MOODLE_18_STABLE

lib/accesslib.php

index c77a339ace6d9d3aaa00704e0ede14089ee17a8a..fcc7ec7538dbd5b670a6e8dc741e904241811ee2 100755 (executable)
@@ -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) {