Commit 5b3fc7fb authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Notify members when a group is deleted (bug #845293)



Made optional in the group_delete function in case this is too
heavy a load when deleting multiple groups from the webservice
api.

Change-Id: Ifd70b30bc3037ead29d01881c08a38b7b2cc5d56
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent ca6e328a
......@@ -201,6 +201,8 @@ $string['notmembermayjoin'] = 'You must join the group \'%s\' to see this page.'
$string['declinerequestsuccess'] = 'Group membership request has been declined sucessfully.';
$string['notpublic'] = 'This group is not public.';
$string['moregroups'] = 'More groups';
$string['deletegroupnotificationsubject'] = 'The group "%s" was deleted';
$string['deletegroupnotificationmessage'] = 'You were a member of the group %s on %s. This group has now been deleted.';
// Bulk add, invite
$string['addmembers'] = 'Add members';
......
......@@ -982,6 +982,7 @@ class ActivityTypeGroupMessage extends ActivityType {
protected $group;
protected $roles;
protected $deletedgroup;
/**
* @param array $data Parameters:
......@@ -992,9 +993,10 @@ class ActivityTypeGroupMessage extends ActivityType {
require_once('group.php');
parent::__construct($data, $cron);
$members = group_get_member_ids($this->group, isset($this->roles) ? $this->roles : null);
$this->users = activity_get_users($this->get_id(), $members);
$members = group_get_member_ids($this->group, isset($this->roles) ? $this->roles : null, $this->deletedgroup);
if (!empty($members)) {
$this->users = activity_get_users($this->get_id(), $members);
}
}
public function get_required_parameters() {
......
......@@ -644,26 +644,50 @@ function group_get_groups_for_editing($ids=null) {
* {{@internal Maybe later we can have a group_can_be_deleted function if
* necessary}}
*/
function group_delete($groupid, $shortname=null, $institution=null) {
function group_delete($groupid, $shortname=null, $institution=null, $notifymembers=true) {
if (empty($groupid) && !empty($institution) && !is_null($shortname) && strlen($shortname)) {
// External call to delete a group, check permission of $USER.
global $USER;
if (!$USER->can_edit_institution($institution)) {
throw new AccessDeniedException("group_delete: cannot delete a group in this institution");
}
$groupid = get_field('group', 'id', 'shortname', $shortname, 'institution', $institution);
$group = get_record('group', 'shortname', $shortname, 'institution', $institution);
}
else {
$groupid = group_param_groupid($groupid);
$group = get_record('group', 'id', $groupid);
}
if ($notifymembers) {
require_once('activity.php');
activity_occurred('groupmessage', array(
'group' => $group->id,
'deletedgroup' => true,
'strings' => (object) array(
'subject' => (object) array(
'key' => 'deletegroupnotificationsubject',
'section' => 'group',
'args' => array(hsc($group->name)),
),
'message' => (object) array(
'key' => 'deletegroupnotificationmessage',
'section' => 'group',
'args' => array(hsc($group->name), get_config('sitename')),
),
),
));
}
$groupid = group_param_groupid($groupid);
update_record('group',
array(
'deleted' => 1,
'name' => get_field('group', 'name', 'id', $groupid) . '.deleted.' . time(),
'name' => $group->name . '.deleted.' . time(),
'shortname' => null,
'institution' => null,
),
array(
'id' => $groupid,
'id' => $group->id,
)
);
}
......@@ -1825,12 +1849,12 @@ function group_get_user_admintutor_groups() {
return $groups;
}
function group_get_member_ids($group, $roles=null) {
function group_get_member_ids($group, $roles=null, $includedeleted=false) {
$rolesql = is_null($roles) ? '' : (' AND gm.role IN (' . join(',', array_map('db_quote', $roles)) . ')');
return get_column_sql('
SELECT gm.member
FROM {group_member} gm INNER JOIN {group} g ON gm.group = g.id
WHERE g.deleted = 0 AND g.id = ?' . $rolesql,
WHERE g.id = ? ' . ($includedeleted ? '' : ' AND g.deleted = 0') . $rolesql,
array($group)
);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment