Commit 25ae45ea authored by Hugh Davenport's avatar Hugh Davenport
Browse files

Fix delete all notifications to delete only what is filtered



Changed the way the form is used, now when a different filter is
selected the type is updated in the pieform. This allows the pieform
to use the type variable to change the sql update and delete statements

Bug #776778

Change-Id: Idd970d9f925d2ea40bb37b5a4f282e7a30a1cb99
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent ea39b3f0
......@@ -57,6 +57,9 @@ if ($USER->get('admin')) {
}
$type = param_variable('type', 'all');
if ($type == '') {
$type = 'all';
}
if (!isset($options[$type])) {
// Comma-separated list; filter out anything that's not an installed type
$type = join(',', array_unique(array_filter(
......@@ -128,6 +131,8 @@ function showHideMessage(id) {
}
function changeactivitytype() {
var delallform = document.forms['delete_all_notifications'];
delallform.elements['type'].value = this.options[this.selectedIndex].value;
var params = {'type': this.options[this.selectedIndex].value};
sendjsonrequest('index.json.php', params, 'GET', function(data) {
paginator.updateResults(data);
......@@ -168,6 +173,10 @@ $deleteall = pieform(array(
'plugintype' => 'core',
'pluginname' => 'account',
'elements' => array(
'type' => array(
'type' => 'hidden',
'value' => $type,
),
'submit' => array(
'type' => 'submit',
'value' => get_string('deleteallnotifications', 'activity'),
......@@ -178,25 +187,58 @@ $deleteall = pieform(array(
function delete_all_notifications_submit() {
global $USER, $SESSION;
$userid = $USER->get('id');
$type = param_variable('type', 'all');
$typesql = '';
if ($type != 'all') {
// Treat as comma-separated list of activity type names
$types = split(',', preg_replace('/[^a-z,]+/', '', $type));
if ($types) {
$typesql = ' at.name IN (' . join(',', array_map('db_quote', $types)) . ')';
if (in_array('adminmessages', $types)) {
$typesql = '(' . $typesql . ' OR at.admin = 1)';
}
$typesql = ' AND ' . $typesql;
}
}
$from = "
FROM {notification_internal_activity} a
JOIN {activity_type} at ON a.type = at.id
WHERE a.usr = ? $typesql";
$values = array($userid);
db_begin();
$count = count_records('notification_internal_activity', 'usr', $USER->get('id'));
// Remove parent pointers to messages we're about to delete
// Use temp table in subselect for Mysql compat.
execute_sql("
UPDATE {notification_internal_activity}
SET parent = NULL
WHERE parent IN (
SELECT id
FROM (
SELECT id FROM {notification_internal_activity} WHERE usr = ?
) AS temp
)",
array($USER->get('id'))
);
delete_records('notification_internal_activity', 'usr', $USER->get('id'));
$count = 0;
$records = get_records_sql_array('SELECT a.id ' . $from, $values);
if ($records) {
$count = sizeof($records);
$ids = array();
foreach ($records as $row) {
$ids[] = $row->id;
}
// Remove parent pointers to messages we're about to delete
execute_sql('
UPDATE {notification_internal_activity}
SET parent = NULL
WHERE parent IN (
' . join(',', array_map('db_quote', $ids)) . '
)'
);
// delete
execute_sql('
DELETE FROM {notification_internal_activity}
WHERE id IN (
' . join(',', array_map('db_quote', $ids)) . '
)'
);
}
db_commit();
$SESSION->add_ok_msg(get_string('deletednotifications', 'activity', $count));
redirect(get_config('wwwroot') . 'account/activity/index.php');
redirect(get_config('wwwroot') . 'account/activity/index.php?type='.$type);
}
$smarty = smarty(array('paginator'));
......
......@@ -142,7 +142,7 @@ $string['institutioninvitesubject'] = 'You have been invited to join the institu
$string['institutioninvitemessage'] = 'You can confirm your membership of this institution on your Institution Settings Page:';
$string['deleteallnotifications'] = 'Delete all notifications';
$string['reallydeleteallnotifications'] = 'Are you sure you want to delete all your notifications?';
$string['reallydeleteallnotifications'] = 'Are you sure you want to delete all your notifications of this activity type?';
$string['viewsubmittedsubject'] = 'Page submitted to %s';
$string['viewsubmittedmessage'] = '%s has submitted their page "%s" to %s';
......
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