From 0f5f8363d728d33c4542e4575920c1c789bc41c7 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sat, 6 May 2006 16:58:36 +0000 Subject: [PATCH] Now, when a single forum is restored and no user data was created, the initial discussion/post is automatically generated. Bug 5418. (http://moodle.org/bugs/bug.php?op=show&bugid=5418) Merged from MOODLE_16_STABLE --- mod/forum/restorelib.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/mod/forum/restorelib.php b/mod/forum/restorelib.php index 9ab55de526..463aca3d42 100644 --- a/mod/forum/restorelib.php +++ b/mod/forum/restorelib.php @@ -117,6 +117,36 @@ $status = forum_read_restore_mods ($newid,$info,$restore); } } + + // If forum type is single, just recreate the initial discussion/post automatically + // if it hasn't been created still (because no user data was selected on backup or + // restore. + if ($forum->type == 'single' && !record_exists('forum_discussions', 'forum', $newid)) { + //Load forum/lib.php + require_once ($CFG->dirroot.'/mod/forum/lib.php'); + // Calculate the default format + if (can_use_html_editor()) { + $defaultformat = FORMAT_HTML; + } else { + $defaultformat = FORMAT_MOODLE; + } + //Create discussion/post data + $sd = new stdClass; + $sd->course = $forum->course; + $sd->forum = $newid; + $sd->name = $forum->name; + $sd->intro = $forum->intro; + $sd->assessed = $forum->assessed; + $sd->format = $defaultformat; + $sd->mailnow = false; + //Insert dicussion/post data + $sdid = forum_add_discussion($sd, $sd->intro); + //Now, mark the initial post of the discussion as mailed! + if ($sdid) { + set_field ('forum_posts','mailed', '1', 'discussion', $sdid); + } + } + } else { $status = false; } -- 2.39.5