]> git.mjollnir.org Git - moodle.git/commitdiff
Now, when a single forum is restored and no user data was created,
authorstronk7 <stronk7>
Sat, 6 May 2006 16:58:36 +0000 (16:58 +0000)
committerstronk7 <stronk7>
Sat, 6 May 2006 16:58:36 +0000 (16:58 +0000)
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

index 9ab55de52666dd386f268b33e2e350836adc3da3..463aca3d4264f635721ab39b236b247665d81071 100644 (file)
                         $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;
             }