Skip to content

Commit

Permalink
MDL-72767 forum: Stop duplicate digests being created
Browse files Browse the repository at this point in the history
This change is to stop there being a possibility of 2 digests tasks
being created for a user on the day that MDL-72767 is applied.
  • Loading branch information
NeillM committed Nov 1, 2021
1 parent 42171eb commit 653af35
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion mod/forum/db/upgrade.php
Expand Up @@ -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.

Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion mod/forum/version.php
Expand Up @@ -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)

0 comments on commit 653af35

Please sign in to comment.