mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 16:04:25 +02:00
MDL-46881 forum: Defer post visibility check to send time
This commit is contained in:
parent
c0284ccbc6
commit
af48d8bdd6
@ -173,10 +173,6 @@ class cron_task extends \core\task\scheduled_task {
|
||||
$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 @@ class cron_task extends \core\task\scheduled_task {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 @@ class cron_task extends \core\task\scheduled_task {
|
||||
}
|
||||
}
|
||||
|
||||
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) [
|
||||
|
@ -1215,11 +1215,11 @@ class mod_forum_mail_testcase extends advanced_testcase {
|
||||
$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 @@ class mod_forum_mail_testcase extends advanced_testcase {
|
||||
$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);
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ class mod_forum_qanda_testcase extends advanced_testcase {
|
||||
],
|
||||
'otheruser' => (object) [
|
||||
'userid' => $otheruser->id,
|
||||
'messages' => 1,
|
||||
'messages' => 3,
|
||||
],
|
||||
'editingteacher' => (object) [
|
||||
'userid' => $editingteacher->id,
|
||||
|
Loading…
x
Reference in New Issue
Block a user