MDL-72767 forum: Stop duplicate digests being created

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.
This commit is contained in:
Neill Magill 2021-10-11 09:32:00 +01:00
parent 42171eb435
commit 653af355dc
2 changed files with 31 additions and 2 deletions

View File

@ -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;
}

View File

@ -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)