mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
MDL-9983 role_unassign should not touch group members table directly - we need events; merged from MOODLE_19_STABLE
This commit is contained in:
parent
96608a55bd
commit
ffc670d931
@ -259,19 +259,37 @@ function groups_delete_grouping($groupingorid) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all users from all groups in course
|
||||
* Remove all users (or one user) from all groups in course
|
||||
* @param int $courseid
|
||||
* @param int $userid 0 means all users
|
||||
* @param bool $showfeedback
|
||||
* @return bool success
|
||||
*/
|
||||
function groups_delete_group_members($courseid, $showfeedback=false) {
|
||||
function groups_delete_group_members($courseid, $userid=0, $showfeedback=false) {
|
||||
global $DB;
|
||||
|
||||
$groupssql = "SELECT id FROM {groups} g WHERE g.courseid = ?";
|
||||
$DB->delete_records_select('groups_members', "groupid IN ($groupssql)", array($courseid));
|
||||
if (is_bool($userid)) {
|
||||
debugging('Incorrect userid function parameter');
|
||||
return false;
|
||||
}
|
||||
|
||||
$params = array('courseid'=>$courseid);
|
||||
|
||||
if ($userid) {
|
||||
$usersql = "AND userid = :userid";
|
||||
$params['userid'] = $userid;
|
||||
} else {
|
||||
$usersql = "";
|
||||
}
|
||||
|
||||
$groupssql = "SELECT id FROM {groups} g WHERE g.courseid = :courseid";
|
||||
$DB->delete_records_select('groups_members', "groupid IN ($groupssql) $usersql", $params);
|
||||
|
||||
//trigger groups events
|
||||
events_trigger('groups_members_removed', $courseid);
|
||||
$eventdata = new object();
|
||||
$eventdata->courseid = $courseid;
|
||||
$eventdata->userid = $userid;
|
||||
events_trigger('groups_members_removed', $eventdata);
|
||||
|
||||
if ($showfeedback) {
|
||||
notify(get_string('deleted').' groups_members');
|
||||
@ -314,7 +332,7 @@ function groups_delete_groups($courseid, $showfeedback=false) {
|
||||
|
||||
// delete any uses of groups
|
||||
groups_delete_groupings_groups($courseid, $showfeedback);
|
||||
groups_delete_group_members($courseid, $showfeedback);
|
||||
groups_delete_group_members($courseid, 0, $showfeedback);
|
||||
|
||||
// delete group pictures
|
||||
if ($groups = $DB->get_records('groups', array('courseid'=>$courseid))) {
|
||||
|
@ -2646,6 +2646,7 @@ function get_roles_with_capability($capability, $permission=NULL, $context='') {
|
||||
*/
|
||||
function role_assign($roleid, $userid, $groupid, $contextid, $timestart=0, $timeend=0, $hidden=0, $enrol='manual',$timemodified='') {
|
||||
global $USER, $CFG, $DB;
|
||||
require_once($CFG->dirroot.'/group/lib.php');
|
||||
|
||||
/// Do some data validation
|
||||
|
||||
@ -2837,11 +2838,7 @@ function role_unassign($roleid=0, $userid=0, $groupid=0, $contextid=0, $enrol=NU
|
||||
// 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 = groups_get_all_groups($context->instanceid)) {
|
||||
foreach ($groups as $group) {
|
||||
$DB->delete_records('groups_members', array('groupid'=>$group->id, 'userid'=>$ra->userid));
|
||||
}
|
||||
}
|
||||
groups_delete_group_members($context->instanceid, $ra->userid);
|
||||
|
||||
// delete lastaccess records
|
||||
$DB->delete_records('user_lastaccess', array('userid'=>$ra->userid, 'courseid'=>$context->instanceid));
|
||||
|
@ -64,7 +64,7 @@ groups_grouping_created - object groups_grouping table record
|
||||
groups_grouping_updated - object groups_grouping table record
|
||||
groups_grouping_deleted - object groups_grouping table record
|
||||
|
||||
groups_members_removed - int course id - removed all members from all groups in course
|
||||
groups_members_removed - object courseid+userid - removed all users (or one user) from all groups in course
|
||||
groups_groupings_groups_removed - int course id - removed all groups from all groupings in course
|
||||
groups_groups_deleted - int course id - deleted all course groups
|
||||
groups_groupings_deleted - int course id - deleted all course groupings
|
||||
|
@ -3697,7 +3697,7 @@ function reset_course_userdata($data) {
|
||||
|
||||
// remove all group members
|
||||
if (!empty($data->reset_groups_members)) {
|
||||
groups_delete_group_members($data->courseid, false);
|
||||
groups_delete_group_members($data->courseid);
|
||||
$status[] = array('component'=>$componentstr, 'item'=>get_string('removegroupsmembers', 'group'), 'error'=>false);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user