Skip to content

Commit

Permalink
MDL-46881 forum: Ensure that there are posts to remove
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jan 29, 2019
1 parent b231aab commit c0284cc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
22 changes: 21 additions & 1 deletion mod/forum/classes/task/send_user_digests.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ protected function prepare_data(int $timenow) {
}
$posts->close();

if (empty($discussionids)) {
// All posts have been removed since the task was queued.
$this->empty_queue($this->recipient->id, $timenow);
return;
}

list($in, $params) = $DB->get_in_or_equal($discussionids);
$this->discussions = $DB->get_records_select('forum_discussions', "id {$in}", $params);

Expand All @@ -321,7 +327,21 @@ protected function prepare_data(int $timenow) {

$this->fill_digest_cache();

$DB->delete_records_select('forum_queue', "userid = :userid AND timemodified < :timemodified", $queueparams);
$this->empty_queue($this->recipient->id, $timenow);
}

/**
* Empty the queue of posts for this user.
*
* @param array $queueparams The list of
*/
protected function empty_queue(int $userid, int $timemodified) : void {
global $DB;

$DB->delete_records_select('forum_queue', "userid = :userid AND timemodified < :timemodified", [
'userid' => $userid,
'timemodified' => $timemodified,
]);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions mod/forum/classes/task/send_user_notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ protected function prepare_data(array $postids) {
}
$posts->close();

if (empty($discussionids)) {
// All posts have been removed since the task was queued.
return;
}

// Fetch all discussions.
list($in, $params) = $DB->get_in_or_equal(array_values($discussionids));
$this->discussions = $DB->get_records_select('forum_discussions', "id {$in}", $params);
Expand Down

0 comments on commit c0284cc

Please sign in to comment.