Permalink
Browse files

MDL-16262 recovery of broken single simple discussions after old rese…

…t; backported from HEAD
  • Loading branch information...
1 parent 7685016 commit 33698217a3abde6e29d7f6035a7b465e2786ad94 skodak committed Jan 1, 2009
Showing with 17 additions and 1 deletion.
  1. +17 −1 mod/forum/lib.php
View
18 mod/forum/lib.php
@@ -125,7 +125,23 @@ function forum_update_instance($forum) {
notify('Warning! There is more than one discussion in this forum - using the most recent');
$discussion = array_pop($discussions);
} else {
- error('Could not find the discussion in this forum');
+ // try to recover by creating initial discussion - MDL-16262
+ $discussion = new object();
+ $discussion->course = $forum->course;
+ $discussion->forum = $forum->id;
+ $discussion->name = $forum->name;
+ $discussion->intro = $forum->intro;
+ $discussion->assessed = $forum->assessed;
+ $discussion->format = $forum->type;
+ $discussion->mailnow = false;
+ $discussion->groupid = -1;
+
+ forum_add_discussion($discussion, $discussion->intro);
+
+ if (! $discussion = get_record('forum_discussions', 'forum', $forum->id)) {
+ error('Could not add the discussion for this forum');
+ }
+
}
}
if (! $post = get_record('forum_posts', 'id', $discussion->firstpost)) {

0 comments on commit 3369821

Please sign in to comment.