Skip to content

Commit

Permalink
Added a timemodified field to forum_queue, and we now delete records
Browse files Browse the repository at this point in the history
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
  • Loading branch information
moodler committed Oct 10, 2007
1 parent 0baafc1 commit f3c3a4d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
13 changes: 7 additions & 6 deletions mod/forum/db/install.xml
Original file line number Diff line number Diff line change
@@ -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"
>
Expand All @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -139,7 +140,7 @@
<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"/>
Expand All @@ -154,7 +155,7 @@
<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"/>
Expand All @@ -179,4 +180,4 @@
</SENTENCES>
</STATEMENT>
</STATEMENTS>
</XMLDB>
</XMLDB>
12 changes: 12 additions & 0 deletions mod/forum/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 6 additions & 1 deletion mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down Expand Up @@ -493,14 +494,18 @@ 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);
}

$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) {

Expand Down
2 changes: 1 addition & 1 deletion mod/forum/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit f3c3a4d

Please sign in to comment.