From f3c3a4d3b13c830c9a8a9713236b5fb1b7032879 Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 10 Oct 2007 02:52:25 +0000 Subject: [PATCH] Added a timemodified field to forum_queue, and we now delete records that are older than a week before processing digests. After upgrade it's possible that some posts will be lost this way but on the other hand it ensures that sites with problems like moodle.org had will start working again. We still need a recordset added to the digestposts loop. MDL-11657 --- mod/forum/db/install.xml | 13 +++++++------ mod/forum/db/upgrade.php | 12 ++++++++++++ mod/forum/lib.php | 7 ++++++- mod/forum/version.php | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/mod/forum/db/install.xml b/mod/forum/db/install.xml index 23fa4d0d9f..9ca99574ef 100644 --- a/mod/forum/db/install.xml +++ b/mod/forum/db/install.xml @@ -1,5 +1,5 @@ - @@ -26,7 +26,7 @@ - + @@ -87,7 +87,8 @@ - + + @@ -139,7 +140,7 @@ - + @@ -154,7 +155,7 @@ - + @@ -179,4 +180,4 @@ - + \ No newline at end of file diff --git a/mod/forum/db/upgrade.php b/mod/forum/db/upgrade.php index f7c24c7f91..199e53cfa5 100644 --- a/mod/forum/db/upgrade.php +++ b/mod/forum/db/upgrade.php @@ -40,6 +40,18 @@ function xmldb_forum_upgrade($oldversion=0) { $db->debug = true; } + if ($result && $oldversion < 2007101000) { + + /// Define field timemodified to be added to forum_queue + $table = new XMLDBTable('forum_queue'); + $field = new XMLDBField('timemodified'); + $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'postid'); + + /// Launch add field timemodified + $result = $result && add_field($table, $field); + } + + return $result; } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 30c53af9ad..1b76756757 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -419,6 +419,7 @@ function forum_cron() { $queue->userid = $userto->id; $queue->discussionid = $discussion->id; $queue->postid = $post->id; + $queue->timemodified = $post->modified; if (!insert_record('forum_queue', $queue)) { mtrace("Error: mod/forum/cron.php: Could not queue for digest mail for id $post->id to user $userto->id ($userto->email) .. not trying again."); } @@ -493,6 +494,8 @@ function forum_cron() { // Now see if there are any digest mails waiting to be sent, and if we should send them + mtrace('Starting digest processing...'); + if (!isset($CFG->digestmailtimelast)) { // To catch the first time set_config('digestmailtimelast', 0); } @@ -500,7 +503,9 @@ function forum_cron() { $timenow = time(); $digesttime = usergetmidnight($timenow, $sitetimezone) + ($CFG->digestmailtime * 3600); - mtrace('Starting digest processing...'); + // Delete any really old ones (normally there shouldn't be any) + $weekago = $timenow - (7 * 24 * 3600); + delete_records_select('forum_queue', "timemodified < $weekago"); if ($CFG->digestmailtimelast < $digesttime and $timenow > $digesttime) { diff --git a/mod/forum/version.php b/mod/forum/version.php index e54cd9ef60..a632e8ed54 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2007072200; +$module->version = 2007101000; $module->requires = 2007072200; // Requires this Moodle version $module->cron = 60; -- 2.39.5