Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…t; backported from HEAD
  • Loading branch information...
commit 33698217a3abde6e29d7f6035a7b465e2786ad94 1 parent 7685016
skodak authored

Showing 1 changed file with 17 additions and 1 deletion. Show diff stats Hide diff stats

  1. +17 1 mod/forum/lib.php
18 mod/forum/lib.php
@@ -125,7 +125,23 @@ function forum_update_instance($forum) {
125 125 notify('Warning! There is more than one discussion in this forum - using the most recent');
126 126 $discussion = array_pop($discussions);
127 127 } else {
128   - error('Could not find the discussion in this forum');
  128 + // try to recover by creating initial discussion - MDL-16262
  129 + $discussion = new object();
  130 + $discussion->course = $forum->course;
  131 + $discussion->forum = $forum->id;
  132 + $discussion->name = $forum->name;
  133 + $discussion->intro = $forum->intro;
  134 + $discussion->assessed = $forum->assessed;
  135 + $discussion->format = $forum->type;
  136 + $discussion->mailnow = false;
  137 + $discussion->groupid = -1;
  138 +
  139 + forum_add_discussion($discussion, $discussion->intro);
  140 +
  141 + if (! $discussion = get_record('forum_discussions', 'forum', $forum->id)) {
  142 + error('Could not add the discussion for this forum');
  143 + }
  144 +
129 145 }
130 146 }
131 147 if (! $post = get_record('forum_posts', 'id', $discussion->firstpost)) {

0 comments on commit 3369821

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