Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…o MOODLE_23_STABLE
  • Loading branch information...
commit de0917ef7fa4f677dff18cc47c4ff87c9c97bc02 2 parents b748564 + b5163c5
@samhemelryk samhemelryk authored
Showing with 31 additions and 18 deletions.
  1. +23 −17 mod/forum/lib.php
  2. +8 −1 mod/forum/post.php
View
40 mod/forum/lib.php
@@ -7060,21 +7060,26 @@ function forum_get_separate_modules($courseid) {
}
/**
- * @global object
- * @global object
- * @global object
- * @param object $forum
- * @param object $cm
- * @return bool
+ * Handles the situation where the user has reached the blocking or warning threshold.
+ * The function will either echo out a message, or throw an exception depending on the
+ * threshold reached (warning or blocked). If the forum passed is invalid false is
+ * returned, otherwise if no restriction is needed true is returned.
+ *
+ * @param int|stdClass $forum the forum id or the forum object
+ * @param stdClass $cm the course module
+ * @param bool $display do we want to echo out the message?
+ * @return bool returns false if $forum is invalid or true
+ * if there is no message to show.
*/
-function forum_check_throttling($forum, $cm=null) {
+function forum_check_throttling($forum, $cm = null, $display = true) {
global $USER, $CFG, $DB, $OUTPUT;
if (is_numeric($forum)) {
$forum = $DB->get_record('forum',array('id'=>$forum));
}
+
if (!is_object($forum)) {
- return false; // this is broken.
+ return false; // This is broken.
}
if (empty($forum->blockafter)) {
@@ -7092,18 +7097,18 @@ function forum_check_throttling($forum, $cm=null) {
}
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
- if(has_capability('mod/forum:postwithoutthrottling', $modcontext)) {
+ if (has_capability('mod/forum:postwithoutthrottling', $modcontext)) {
return true;
}
- // get the number of posts in the last period we care about
+ // Get the number of posts in the last period we care about.
$timenow = time();
$timeafter = $timenow - $forum->blockperiod;
- $numposts = $DB->count_records_sql('SELECT COUNT(p.id) FROM {forum_posts} p'
- .' JOIN {forum_discussions} d'
- .' ON p.discussion = d.id WHERE d.forum = ?'
- .' AND p.userid = ? AND p.created > ?', array($forum->id, $USER->id, $timeafter));
+ $numposts = $DB->count_records_sql('SELECT COUNT(p.id) FROM {forum_posts} p
+ JOIN {forum_discussions} d
+ ON p.discussion = d.id WHERE d.forum = ?
+ AND p.userid = ? AND p.created > ?', array($forum->id, $USER->id, $timeafter));
$a = new stdClass();
$a->blockafter = $forum->blockafter;
@@ -7113,11 +7118,12 @@ function forum_check_throttling($forum, $cm=null) {
if ($forum->blockafter <= $numposts) {
print_error('forumblockingtoomanyposts', 'error', $CFG->wwwroot.'/mod/forum/view.php?f='.$forum->id, $a);
}
+
if ($forum->warnafter <= $numposts) {
- echo $OUTPUT->notification(get_string('forumblockingalmosttoomanyposts','forum',$a));
+ if ($display) {
+ echo $OUTPUT->notification(get_string('forumblockingalmosttoomanyposts', 'forum', $a));
+ }
}
-
-
}
View
9 mod/forum/post.php
@@ -680,7 +680,11 @@
} else if ($fromform->discussion) { // Adding a new post to an existing discussion
+ // Before we add this we must check that the user will not exceed the blocking threshold.
+ forum_check_throttling($forum, $cm, false);
+
unset($fromform->groupid);
+
$message = '';
$addpost = $fromform;
$addpost->forum=$forum->id;
@@ -728,7 +732,10 @@
}
exit;
- } else { // Adding a new discussion
+ } else { // Adding a new discussion.
+ // Before we add this we must check that the user will not exceed the blocking threshold.
+ forum_check_throttling($forum, $cm, false);
+
if (!forum_user_can_post_discussion($forum, $fromform->groupid, -1, $cm, $modcontext)) {
print_error('cannotcreatediscussion', 'forum');
}
Please sign in to comment.
Something went wrong with that request. Please try again.