Skip to content

Commit

Permalink
MDL-64400 core_messages: Allow cron to delete unread notifications too
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaia Anabitarte committed Dec 27, 2018
1 parent 7f234ac commit f10c293
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
24 changes: 22 additions & 2 deletions admin/settings/subsystems.php
Expand Up @@ -21,8 +21,28 @@
0)
);

$options = array(DAYSECS=>new lang_string('secondstotime86400'), WEEKSECS=>new lang_string('secondstotime604800'), 2620800=>new lang_string('nummonths', 'moodle', 1), 15724800=>new lang_string('nummonths', 'moodle', 6),0=>new lang_string('never'));
$optionalsubsystems->add(new admin_setting_configselect('messagingdeletereadnotificationsdelay', new lang_string('messagingdeletereadnotificationsdelay', 'admin'), new lang_string('configmessagingdeletereadnotificationsdelay', 'admin'), 604800, $options));
$options = array(
DAYSECS => new lang_string('secondstotime86400'),
WEEKSECS => new lang_string('secondstotime604800'),
2620800 => new lang_string('nummonths', 'moodle', 1),
7862400 => new lang_string('nummonths', 'moodle', 3),
15724800 => new lang_string('nummonths', 'moodle', 6),
0 => new lang_string('never')
);
$optionalsubsystems->add(new admin_setting_configselect(
'messagingdeletereadnotificationsdelay',
new lang_string('messagingdeletereadnotificationsdelay', 'admin'),
new lang_string('configmessagingdeletereadnotificationsdelay', 'admin'),
604800,
$options)
);
$optionalsubsystems->add(new admin_setting_configselect(
'messagingdeleteallnotificationsdelay',
new lang_string('messagingdeleteallnotificationsdelay', 'admin'),
new lang_string('configmessagingdeleteallnotificationsdelay', 'admin'),
2620800,
$options)
);

$optionalsubsystems->add(new admin_setting_configcheckbox('messagingallowemailoverride', new lang_string('messagingallowemailoverride', 'admin'), new lang_string('configmessagingallowemailoverride','admin'), 0));

Expand Down
2 changes: 2 additions & 0 deletions lang/en/admin.php
Expand Up @@ -280,6 +280,7 @@
$string['configmessaging'] = 'If enabled, users can send messages to other users on the site.';
$string['configmessagingallowemailoverride'] = 'Allow users to have email message notifications sent to an email address other than the email address in their profile';
$string['configmessagingdeletereadnotificationsdelay'] = 'Read notifications can be deleted to save space. How long after a notification is read can it be deleted?';
$string['configmessagingdeleteallnotificationsdelay'] = 'Read and unread notifications can be deleted to save space. How long after a notification is created can it be deleted?';
$string['configmessagingallusers'] = 'If enabled, users can view the list of all users on the site when selecting someone to message, and their message preferences include the option to accept messages from anyone on the site. If disabled, users can only view the list of users in their courses, and they have just two options in message preferences - to accept messages from their contacts only, or their contacts and anyone in their courses.';
$string['configminpassworddigits'] = 'Passwords must have at least these many digits.';
$string['configminpasswordlength'] = 'Passwords must be at least these many characters long.';
Expand Down Expand Up @@ -769,6 +770,7 @@
$string['messagingallowemailoverride'] = 'Notification email override';
$string['messagingallusers'] = 'Allow site-wide messaging';
$string['messagingdeletereadnotificationsdelay'] = 'Delete read notifications';
$string['messagingdeleteallnotificationsdelay'] = 'Delete all notifications';
$string['minpassworddigits'] = 'Digits';
$string['minpasswordlength'] = 'Password length';
$string['minpasswordlower'] = 'Lowercase letters';
Expand Down
11 changes: 8 additions & 3 deletions lib/classes/task/messaging_cleanup_task.php
Expand Up @@ -46,13 +46,18 @@ public function execute() {

$timenow = time();

// Cleanup messaging.
// Cleanup read and unread notifications.
if (!empty($CFG->messagingdeleteallnotificationsdelay)) {
$notificationdeletetime = $timenow - $CFG->messagingdeleteallnotificationsdelay;
$params = array('notificationdeletetime' => $notificationdeletetime);
$DB->delete_records_select('notifications', 'timecreated < :notificationdeletetime', $params);
}

// Cleanup read notifications.
if (!empty($CFG->messagingdeletereadnotificationsdelay)) {
$notificationdeletetime = $timenow - $CFG->messagingdeletereadnotificationsdelay;
$params = array('notificationdeletetime' => $notificationdeletetime);
$DB->delete_records_select('notifications', 'timeread < :notificationdeletetime', $params);
}

}

}
1 change: 1 addition & 0 deletions mod/forum/tests/mail_test.php
Expand Up @@ -287,6 +287,7 @@ public function test_cron_message_includes_courseid() {
// Reset the message sink for other tests.
$this->helper->messagesink = $this->redirectMessages();
$event = reset($events);

$this->assertEquals($course->id, $event->other['courseid']);
}

Expand Down

0 comments on commit f10c293

Please sign in to comment.