Index: lib/moodlelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/moodlelib.php,v retrieving revision 1.790 diff -u -r1.790 moodlelib.php --- lib/moodlelib.php 20 Nov 2006 16:45:24 -0000 1.790 +++ lib/moodlelib.php 20 Nov 2006 16:58:55 -0000 @@ -1903,11 +1903,11 @@ // Get the context of the metacourse. $context = get_context_instance(CONTEXT_COURSE, $course->id); // SITEID can not be a metacourse - // We do not ever want to unassign the list of metacourse manager, so get a list of them. - if ($users = get_users_by_capability($context, 'moodle/course:managemetacourse')) { - $managers = array_keys($users); + // We do not ever want to unassign metacourse managers, so get a list of those roles. + if ($managerroles = get_roles_with_capability('moodle/course:managemetacourse')) { + $managerrolestest = 'ra.roleid NOT IN (' . implode(',', array_keys($managerroles)) . ') AND'; } else { - $managers = array(); + $managerrolestest = ''; } // Get assignments of a user to a role that exist in a child course, but @@ -1945,6 +1945,7 @@ {$CFG->prefix}role_assignments ra WHERE ra.contextid = {$context->id} AND + $managerrolestest NOT EXISTS ( SELECT 1 FROM {$CFG->prefix}role_assignments ra2, @@ -1966,9 +1967,7 @@ // Make the unassignments, if they are not managers. foreach ($unassignments as $unassignment) { - if (!in_array($unassignment->userid, $managers)) { - $success = role_unassign($unassignment->roleid, $unassignment->userid, 0, $context->id) && $success; - } + $success = role_unassign($unassignment->roleid, $unassignment->userid, 0, $context->id) && $success; } // Make the assignments.