Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'MDL-39303_m24' of https://github.com/markn86/moodle int…

…o MOODLE_24_STABLE
  • Loading branch information...
commit 7de740be35c594b5d1e052b02b0fa3f2ac466c02 2 parents 7e1c6bf + ee02d17
Sam Hemelryk samhemelryk authored

Showing 2 changed files with 31 additions and 18 deletions. Show diff stats Hide diff stats

  1. +23 17 mod/forum/lib.php
  2. +8 1 mod/forum/post.php
40 mod/forum/lib.php
@@ -7063,21 +7063,26 @@ function forum_get_post_actions() {
7063 7063 }
7064 7064
7065 7065 /**
7066   - * @global object
7067   - * @global object
7068   - * @global object
7069   - * @param object $forum
7070   - * @param object $cm
7071   - * @return bool
  7066 + * Handles the situation where the user has reached the blocking or warning threshold.
  7067 + * The function will either echo out a message, or throw an exception depending on the
  7068 + * threshold reached (warning or blocked). If the forum passed is invalid false is
  7069 + * returned, otherwise if no restriction is needed true is returned.
  7070 + *
  7071 + * @param int|stdClass $forum the forum id or the forum object
  7072 + * @param stdClass $cm the course module
  7073 + * @param bool $display do we want to echo out the message?
  7074 + * @return bool returns false if $forum is invalid or true
  7075 + * if there is no message to show.
7072 7076 */
7073   -function forum_check_throttling($forum, $cm=null) {
  7077 +function forum_check_throttling($forum, $cm = null, $display = true) {
7074 7078 global $USER, $CFG, $DB, $OUTPUT;
7075 7079
7076 7080 if (is_numeric($forum)) {
7077 7081 $forum = $DB->get_record('forum',array('id'=>$forum));
7078 7082 }
  7083 +
7079 7084 if (!is_object($forum)) {
7080   - return false; // this is broken.
  7085 + return false; // This is broken.
7081 7086 }
7082 7087
7083 7088 if (empty($forum->blockafter)) {
@@ -7095,18 +7100,18 @@ function forum_check_throttling($forum, $cm=null) {
7095 7100 }
7096 7101
7097 7102 $modcontext = context_module::instance($cm->id);
7098   - if(has_capability('mod/forum:postwithoutthrottling', $modcontext)) {
  7103 + if (has_capability('mod/forum:postwithoutthrottling', $modcontext)) {
7099 7104 return true;
7100 7105 }
7101 7106
7102   - // get the number of posts in the last period we care about
  7107 + // Get the number of posts in the last period we care about.
7103 7108 $timenow = time();
7104 7109 $timeafter = $timenow - $forum->blockperiod;
7105 7110
7106   - $numposts = $DB->count_records_sql('SELECT COUNT(p.id) FROM {forum_posts} p'
7107   - .' JOIN {forum_discussions} d'
7108   - .' ON p.discussion = d.id WHERE d.forum = ?'
7109   - .' AND p.userid = ? AND p.created > ?', array($forum->id, $USER->id, $timeafter));
  7111 + $numposts = $DB->count_records_sql('SELECT COUNT(p.id) FROM {forum_posts} p
  7112 + JOIN {forum_discussions} d
  7113 + ON p.discussion = d.id WHERE d.forum = ?
  7114 + AND p.userid = ? AND p.created > ?', array($forum->id, $USER->id, $timeafter));
7110 7115
7111 7116 $a = new stdClass();
7112 7117 $a->blockafter = $forum->blockafter;
@@ -7116,11 +7121,12 @@ function forum_check_throttling($forum, $cm=null) {
7116 7121 if ($forum->blockafter <= $numposts) {
7117 7122 print_error('forumblockingtoomanyposts', 'error', $CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id, $a);
7118 7123 }
  7124 +
7119 7125 if ($forum->warnafter <= $numposts) {
7120   - echo $OUTPUT->notification(get_string('forumblockingalmosttoomanyposts','forum',$a));
  7126 + if ($display) {
  7127 + echo $OUTPUT->notification(get_string('forumblockingalmosttoomanyposts', 'forum', $a));
  7128 + }
7121 7129 }
7122   -
7123   -
7124 7130 }
7125 7131
7126 7132
9 mod/forum/post.php
@@ -680,7 +680,11 @@
680 680
681 681
682 682 } else if ($fromform->discussion) { // Adding a new post to an existing discussion
  683 + // Before we add this we must check that the user will not exceed the blocking threshold.
  684 + forum_check_throttling($forum, $cm, false);
  685 +
683 686 unset($fromform->groupid);
  687 +
684 688 $message = '';
685 689 $addpost = $fromform;
686 690 $addpost->forum=$forum->id;
@@ -728,7 +732,10 @@
728 732 }
729 733 exit;
730 734
731   - } else { // Adding a new discussion
  735 + } else { // Adding a new discussion.
  736 + // Before we add this we must check that the user will not exceed the blocking threshold.
  737 + forum_check_throttling($forum, $cm, false);
  738 +
732 739 if (!forum_user_can_post_discussion($forum, $fromform->groupid, -1, $cm, $modcontext)) {
733 740 print_error('cannotcreatediscussion', 'forum');
734 741 }

0 comments on commit 7de740b

Please sign in to comment.
Something went wrong with that request. Please try again.