]> git.mjollnir.org Git - moodle.git/commitdiff
Fixes bug #619 -- moving discussions wasn't moving attachments
authormoodler <moodler>
Sun, 17 Aug 2003 14:46:44 +0000 (14:46 +0000)
committermoodler <moodler>
Sun, 17 Aug 2003 14:46:44 +0000 (14:46 +0000)
mod/forum/discuss.php
mod/forum/lib.php

index 2b8cf0d9e85b7a523957edd5569bbe113849e314..60cf79ef42cb21fee5a2fc3913ab46b5aeebaeab 100644 (file)
@@ -28,6 +28,9 @@
             error("Only teachers can do that!");
         }
         if ($forum = get_record("forum", "id", $move)) {
+            if (!forum_move_attachments($discussion, $move)) {
+                notify("Errors occurred while moving attachment directories - check your file permissions");
+            }
             set_field("forum_discussions", "forum", $forum->id, "id", $discussion->id);
             $discussion->forum = $forum->id;
             add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id");
index f68c8ff014c84d7c13a01c977220772a781925be..88436d584116e2fb40557ac644d201d672d00dfc 100644 (file)
@@ -1357,6 +1357,34 @@ function forum_delete_old_attachments($post, $exception="") {
     }
 }
 
+function forum_move_attachments($discussion, $forumid) {
+/// Given a discussion object that is being moved to forumid, 
+/// this function checks all posts in that discussion 
+/// for attachments, and if any are found, these are 
+/// moved to the new forum directory.
+
+    global $CFG;
+
+    $return = true;
+
+    if ($posts = get_records_select("forum_posts", "discussion = '$discussion->id' AND attachment <> ''")) {
+        foreach ($posts as $oldpost) {
+            $oldpost->course = $discussion->course;
+            $oldpost->forum = $discussion->forum;
+            $oldpostdir = "$CFG->dataroot/".forum_file_area_name($oldpost);
+            if (is_dir($oldpostdir)) {
+                $newpost = $oldpost;
+                $newpost->forum = $forumid;
+                $newpostdir = "$CFG->dataroot/".forum_file_area_name($newpost);
+                if (! @rename($oldpostdir, $newpostdir)) {
+                    $return = false;
+                }
+            }
+        }
+    }
+    return $return;
+}
+
 function forum_print_attachments($post, $return=NULL) {
 // if return=html, then return a html string.
 // if return=text, then return a text-only string.