diff --git a/mod/forum/classes/task/cron_task.php b/mod/forum/classes/task/cron_task.php index ee2d2961934b4..2d0fd60a803a0 100644 --- a/mod/forum/classes/task/cron_task.php +++ b/mod/forum/classes/task/cron_task.php @@ -173,10 +173,6 @@ protected function process_post_data($posts) { $this->fill_digest_cache(); $this->log_finish("Done", 1); - $this->log_start("Filling user posted cache for Q&A forums", 1); - $this->fetch_user_has_posted(); - $this->log_finish("Done", 1); - $this->log_start("Queueing user tasks."); $this->queue_user_tasks(); $this->log_finish("All tasks queued.", 1); @@ -311,44 +307,6 @@ protected function fill_user_subscription_cache() { } } - /** - * Fill the cache for Q&A forums. - */ - protected function fetch_user_has_posted() { - global $DB; - - $forums = array_filter($this->forums, function($forum) { - return $forum->type === 'qanda'; - }); - - if (empty($forums)) { - return; - } - - list($in, $params) = $DB->get_in_or_equal(array_keys($forums)); - - $sql = "SELECT d.forum, d.firstpost, p.userid - FROM {forum} f - INNER JOIN {forum_discussions} d ON d.forum = f.id - LEFT JOIN {forum_posts} p ON p.discussion = d.id - WHERE f.type = 'qanda' - AND f.id {$in} - GROUP BY p.userid, d.forum, d.firstpost"; - - $rs = $DB->get_recordset_sql($sql, $params); - foreach ($rs as $row) { - if (empty($this->qandametadata[$row->forum])) { - $this->qandametadata[$row->forum] = (object) [ - 'users' => [], - 'firstpost' => [$row->firstpost], - ]; - } - $this->qandametadata[$row->forum]->users[$row->userid] = true; - } - $rs->close(); - - } - /** * Queue the user tasks. */ @@ -500,22 +458,6 @@ protected function fetch_posts_for_user($user) { } } - if ($forum->type === 'qanda' && $postid != $discussion->firstpost) { - $hasqandapost = isset($this->qandametadata[$forumid]); - $hasqandapost = $hasqandapost && isset($this->qandametadata[$forumid]->users[$user->id]); - if (!$hasqandapost) { - // The user has not posted to this qanda forum. - unset($poststructure[$courseid][$forumid][$discussionid]); - continue; - } - } - - if (!forum_user_can_see_post($forum, $discussion, $post, null, $cm)) { - // The user is not allowed to see the post for some other reason. - unset($poststructure[$courseid][$forumid][$discussionid][$postid]); - continue; - } - if ($maildigest > 0) { // This user wants the mails to be in digest form. $digeststructure[] = (object) [ diff --git a/mod/forum/tests/mail_test.php b/mod/forum/tests/mail_test.php index 957a4edcc9d87..8bf818f94baea 100644 --- a/mod/forum/tests/mail_test.php +++ b/mod/forum/tests/mail_test.php @@ -1215,11 +1215,11 @@ public function test_access_coursemodule_hidden() { $expect = [ 'author' => (object) [ 'userid' => $author->id, - 'messages' => 0, + 'messages' => 1, ], 'recipient' => (object) [ 'userid' => $recipient->id, - 'messages' => 0, + 'messages' => 1, ], 'editor' => (object) [ 'userid' => $editor->id, @@ -1229,8 +1229,8 @@ public function test_access_coursemodule_hidden() { $this->queue_tasks_and_assert($expect); // No notifications should be queued. - $this->send_notifications_and_assert($author, []); - $this->send_notifications_and_assert($recipient, []); + $this->send_notifications_and_assert($author, [], true); + $this->send_notifications_and_assert($recipient, [], true); $this->send_notifications_and_assert($editor, [$post], true); } diff --git a/mod/forum/tests/qanda_test.php b/mod/forum/tests/qanda_test.php index 417ea2a8482df..3e4795250ab54 100644 --- a/mod/forum/tests/qanda_test.php +++ b/mod/forum/tests/qanda_test.php @@ -134,7 +134,7 @@ public function test_user_has_not_posted() { ], 'otheruser' => (object) [ 'userid' => $otheruser->id, - 'messages' => 1, + 'messages' => 3, ], 'editingteacher' => (object) [ 'userid' => $editingteacher->id,