]> git.mjollnir.org Git - moodle.git/commitdiff
Added a timemodified field to forum_queue, and we now delete records
authormoodler <moodler>
Wed, 10 Oct 2007 02:52:25 +0000 (02:52 +0000)
committermoodler <moodler>
Wed, 10 Oct 2007 02:52:25 +0000 (02:52 +0000)
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
mod/forum/db/upgrade.php
mod/forum/lib.php
mod/forum/version.php

index 23fa4d0d9f1a7dfe78f6a345c15d1af7584e79c7..9ca99574ef2e3b9276aaa6073433454b5c9107c0 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/forum/db" VERSION="20060828" COMMENT="XMLDB file for Moodle mod/forum"
+<XMLDB PATH="mod/forum/db" VERSION="20071010" COMMENT="XMLDB file for Moodle mod/forum"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
 >
@@ -26,7 +26,7 @@
         <FIELD NAME="blockperiod" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="blockafter"/>
       </FIELDS>
       <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id" />
+        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
       </KEYS>
       <INDEXES>
         <INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
@@ -87,7 +87,8 @@
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="userid"/>
         <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="discussionid"/>
         <FIELD NAME="discussionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="userid" NEXT="postid"/>
-        <FIELD NAME="postid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="discussionid"/>
+        <FIELD NAME="postid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="discussionid" NEXT="timemodified"/>
+        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="The modified time of the original post" PREVIOUS="postid"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="discussionid"/>
         <FIELD NAME="lastread" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="firstread"/>
       </FIELDS>
       <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id" />
+        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
       </KEYS>
       <INDEXES>
         <INDEX NAME="userid-forumid" UNIQUE="false" FIELDS="userid, forumid" NEXT="userid-discussionid"/>
         <FIELD NAME="forumid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="userid"/>
       </FIELDS>
       <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id" />
+        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
       </KEYS>
       <INDEXES>
         <INDEX NAME="userid-forumid" UNIQUE="false" FIELDS="userid, forumid"/>
       </SENTENCES>
     </STATEMENT>
   </STATEMENTS>
-</XMLDB>
+</XMLDB>
\ No newline at end of file
index f7c24c7f91465d257b059e4fbd4b72b2114665bc..199e53cfa58305ac9f225c96701f862861b683e9 100644 (file)
@@ -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;
 }
 
index 30c53af9ad3fb677ba74ddaab2bd95c708d2cebb..1b767567570c378243cc6ef8720c9d33be606215 100644 (file)
@@ -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) {
 
index e54cd9ef60693e87de0bb9224c586481fbc9f8e0..a632e8ed5403ed43f973d37dfe7f6ca75bfe25a9 100644 (file)
@@ -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;