mirror of
https://github.com/moodle/moodle.git
synced 2025-03-26 18:42:40 +01:00
Merge branch 'MDL-72767' of https://github.com/NeillM/moodle
This commit is contained in:
commit
b4fbfb5eb1
mod/forum
@ -336,16 +336,19 @@ class cron_task extends \core\task\scheduled_task {
|
||||
if (!empty($digestpostdata)) {
|
||||
// Insert all of the records for the digest.
|
||||
$DB->insert_records('forum_queue', $digestpostdata);
|
||||
$digesttime = usergetmidnight($timenow, $sitetimezone) + ($CFG->digestmailtime * 3600);
|
||||
$servermidnight = usergetmidnight($timenow, $sitetimezone);
|
||||
$digesttime = $servermidnight + ($CFG->digestmailtime * 3600);
|
||||
|
||||
if ($digesttime < $timenow) {
|
||||
// Digest time is in the past. Get a new time for tomorrow.
|
||||
$digesttime = usergetmidnight($timenow + DAYSECS, $sitetimezone) + ($CFG->digestmailtime * 3600);
|
||||
$servermidnight = usergetmidnight($timenow + DAYSECS, $sitetimezone);
|
||||
$digesttime = $servermidnight + ($CFG->digestmailtime * 3600);
|
||||
}
|
||||
|
||||
$task = new \mod_forum\task\send_user_digests();
|
||||
$task->set_userid($user->id);
|
||||
$task->set_component('mod_forum');
|
||||
$task->set_custom_data(['servermidnight' => $servermidnight]);
|
||||
$task->set_next_run_time($digesttime);
|
||||
\core\task\manager::reschedule_or_queue_adhoc_task($task);
|
||||
$usercounts['digests']++;
|
||||
|
@ -43,7 +43,7 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
function xmldb_forum_upgrade($oldversion) {
|
||||
global $DB;
|
||||
global $CFG, $DB;
|
||||
|
||||
$dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
|
||||
|
||||
@ -255,5 +255,34 @@ function xmldb_forum_upgrade($oldversion) {
|
||||
upgrade_mod_savepoint(true, 2020072100, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2021101100) {
|
||||
// Add custom data to digest tasks to stop duplicates being created after this patch.
|
||||
$timenow = time();
|
||||
|
||||
$sitetimezone = \core_date::get_server_timezone();
|
||||
$servermidnight = usergetmidnight($timenow, $sitetimezone);
|
||||
$digesttime = $servermidnight + ($CFG->digestmailtime * 3600);
|
||||
if ($digesttime < $timenow) {
|
||||
// Digest time is in the past. set for tomorrow.
|
||||
$servermidnight = usergetmidnight($timenow + DAYSECS, $sitetimezone);
|
||||
}
|
||||
|
||||
$customdata = json_encode(['servermidnight' => $servermidnight]);
|
||||
|
||||
$params = [
|
||||
'component' => 'mod_forum',
|
||||
'classname' => '\mod_forum\task\send_user_digests',
|
||||
'customdata' => '', // We do not want to overwrite any tasks that already have the custom data.
|
||||
];
|
||||
|
||||
$textfield = $DB->sql_compare_text('customdata', 1);
|
||||
|
||||
$sql = "component = :component AND classname = :classname AND $textfield = :customdata";
|
||||
|
||||
$DB->set_field_select('task_adhoc', 'customdata', $customdata, $sql, $params);
|
||||
|
||||
upgrade_mod_savepoint(true, 2021101100, 'forum');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -655,7 +655,7 @@ class mod_forum_maildigest_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* The digest being in the past is queued til the next day.
|
||||
* The digest being in the future is queued for today.
|
||||
*/
|
||||
public function test_cron_digest_same_day() {
|
||||
global $DB, $CFG;
|
||||
@ -695,6 +695,73 @@ class mod_forum_maildigest_testcase extends advanced_testcase {
|
||||
$this->assertLessThanOrEqual($digesttime, $task->nextruntime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that if a new message is posted after the days digest time,
|
||||
* but before that days digests are sent a new task is created.
|
||||
*/
|
||||
public function test_cron_digest_queue_next_before_current_processed() {
|
||||
global $DB, $CFG;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Set up a basic user enrolled in a course.
|
||||
$userhelper = $this->helper_setup_user_in_course();
|
||||
$user = $userhelper->user;
|
||||
$forum1 = $userhelper->forums->forum1;
|
||||
|
||||
// Add 1 discussions to forum 1.
|
||||
$this->helper_post_to_forum($forum1, $user, ['mailnow' => 1]);
|
||||
|
||||
// Set the tested user's default maildigest setting.
|
||||
$DB->set_field('user', 'maildigest', 1, ['id' => $user->id]);
|
||||
|
||||
// Set the digest time to the future (magic, shouldn't work).
|
||||
$CFG->digestmailtime = 25;
|
||||
// One digest e-mail should be sent, and no individual notifications.
|
||||
$expect = [
|
||||
(object) [
|
||||
'userid' => $user->id,
|
||||
'digests' => 1,
|
||||
],
|
||||
];
|
||||
$this->queue_tasks_and_assert($expect);
|
||||
|
||||
// Set the digest time to midnight.
|
||||
$CFG->digestmailtime = 0;
|
||||
|
||||
// Add another discussions to forum 1.
|
||||
$this->helper_post_to_forum($forum1, $user, ['mailnow' => 1]);
|
||||
|
||||
// One digest e-mail should be sent, and no individual notifications.
|
||||
$expect = [
|
||||
(object) [
|
||||
'userid' => $user->id,
|
||||
'digests' => 1,
|
||||
],
|
||||
];
|
||||
$this->queue_tasks_and_assert($expect);
|
||||
|
||||
// There should now be two tasks queued.
|
||||
$tasks = $DB->get_records('task_adhoc');
|
||||
$this->assertCount(2, $tasks);
|
||||
|
||||
// Add yet another another discussions to forum 1.
|
||||
$this->helper_post_to_forum($forum1, $user, ['mailnow' => 1]);
|
||||
|
||||
// One digest e-mail should be sent, and no individual notifications.
|
||||
$expect = [
|
||||
(object) [
|
||||
'userid' => $user->id,
|
||||
'digests' => 1,
|
||||
],
|
||||
];
|
||||
$this->queue_tasks_and_assert($expect);
|
||||
|
||||
// There should still be two tasks queued.
|
||||
$tasks = $DB->get_records('task_adhoc');
|
||||
$this->assertCount(2, $tasks);
|
||||
}
|
||||
|
||||
/**
|
||||
* The sending of a digest marks posts as read if automatic message read marking is set.
|
||||
*/
|
||||
|
@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2021052501; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2021101100; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2021052500; // Requires this Moodle version.
|
||||
$plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)
|
||||
|
Loading…
x
Reference in New Issue
Block a user