Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-30421 forum: resolved error in single discussion forum, if more t…

…hen one record is present
  • Loading branch information...
commit cfd9db2b8fbecc0f4c4a4d25f3ee8ff063f63b75 1 parent 779085b
Rajesh Taneja authored
Showing with 32 additions and 35 deletions.
  1. +1 −0  mod/forum/lang/en/forum.php
  2. +25 −24 mod/forum/lib.php
  3. +6 −11 mod/forum/view.php
View
1  mod/forum/lang/en/forum.php
@@ -403,6 +403,7 @@
$string['viewalldiscussions'] = 'View all discussions';
$string['warnafter'] = 'Post threshold for warning';
$string['warnafter_help'] = 'Students can be warned as they approach the maximum number of posts allowed in a given period. This setting specifies after how many posts they are warned. Users with the capability mod/forum:postwithoutthrottling are exempt from post limits.';
+$string['warnformorepost'] = 'Warning! There is more than one discussion in this forum - using the most recent';
$string['yournewquestion'] = 'Your new question';
$string['yournewtopic'] = 'Your new discussion topic';
$string['yourreply'] = 'Your reply';
View
49 mod/forum/lib.php
@@ -151,30 +151,31 @@ function forum_update_instance($forum, $mform) {
}
if ($forum->type == 'single') { // Update related discussion and post.
- if (! $discussion = $DB->get_record('forum_discussions', array('forum'=>$forum->id))) {
- if ($discussions = $DB->get_records('forum_discussions', array('forum'=>$forum->id), 'timemodified ASC')) {
- echo $OUTPUT->notification('Warning! There is more than one discussion in this forum - using the most recent');
- $discussion = array_pop($discussions);
- } else {
- // try to recover by creating initial discussion - MDL-16262
- $discussion = new stdClass();
- $discussion->course = $forum->course;
- $discussion->forum = $forum->id;
- $discussion->name = $forum->name;
- $discussion->assessed = $forum->assessed;
- $discussion->message = $forum->intro;
- $discussion->messageformat = $forum->introformat;
- $discussion->messagetrust = true;
- $discussion->mailnow = false;
- $discussion->groupid = -1;
-
- $message = '';
-
- forum_add_discussion($discussion, null, $message);
-
- if (! $discussion = $DB->get_record('forum_discussions', array('forum'=>$forum->id))) {
- print_error('cannotadd', 'forum');
- }
+ $discussions = $DB->get_records('forum_discussions', array('forum'=>$forum->id), 'timemodified ASC');
+ if (!empty($discussions)) {
+ if (count($discussions) > 1) {
+ echo $OUTPUT->notification(get_string('warnformorepost', 'forum'));
+ }
+ $discussion = array_pop($discussions);
+ } else {
+ // try to recover by creating initial discussion - MDL-16262
+ $discussion = new stdClass();
+ $discussion->course = $forum->course;
+ $discussion->forum = $forum->id;
+ $discussion->name = $forum->name;
+ $discussion->assessed = $forum->assessed;
+ $discussion->message = $forum->intro;
+ $discussion->messageformat = $forum->introformat;
+ $discussion->messagetrust = true;
+ $discussion->mailnow = false;
+ $discussion->groupid = -1;
+
+ $message = '';
+
+ forum_add_discussion($discussion, null, $message);
+
+ if (! $discussion = $DB->get_record('forum_discussions', array('forum'=>$forum->id))) {
+ print_error('cannotadd', 'forum');
}
}
if (! $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost))) {
View
17 mod/forum/view.php
@@ -142,10 +142,10 @@
// If it's a simple single discussion forum, we need to print the display
// mode control.
if ($forum->type == 'single') {
- if (! $discussion = $DB->get_record("forum_discussions", array("forum" => $forum->id))) {
- if ($discussions = $DB->get_records("forum_discussions", array("forum", $forum->id), "timemodified ASC")) {
- $discussion = array_pop($discussions);
- }
+ $discussion = NULL;
+ $discussions = $DB->get_records('forum_discussions', array('forum'=>$forum->id), 'timemodified ASC');
+ if (!empty($discussions)) {
+ $discussion = array_pop($discussions);
}
if ($discussion) {
if ($mode) {
@@ -168,13 +168,8 @@
switch ($forum->type) {
case 'single':
- if (! $discussion = $DB->get_record("forum_discussions", array("forum" => $forum->id))) {
- if ($discussions = $DB->get_records("forum_discussions", array("forum" => $forum->id), "timemodified ASC")) {
- echo $OUTPUT->notification("Warning! There is more than one discussion in this forum - using the most recent");
- $discussion = array_pop($discussions);
- } else {
- print_error('nodiscussions', 'forum');
- }
+ if (!empty($discussions) && count($discussions) > 1) {
+ echo $OUTPUT->notification(get_string('warnformorepost', 'forum'));
}
if (! $post = forum_get_post_full($discussion->firstpost)) {
print_error('cannotfindfirstpost', 'forum');
Please sign in to comment.
Something went wrong with that request. Please try again.