error('Forum not visible', $return);
}
- if (!forum_move_attachments($discussion, $forumto)) {
+ if (!forum_move_attachments($discussion, $forumto->id)) {
notify("Errors occurred while moving attachment directories - check your file permissions");
}
set_field('forum_discussions', 'forum', $forumto->id, 'id', $discussion->id);
// Delete the RSS files for the 2 forums because we want to force
// the regeneration of the feeds since the discussions have been
// moved.
- if (!forum_rss_delete_file($forum) || !forum_rss_delete_file($sourceforum)) {
+ if (!forum_rss_delete_file($forum) || !forum_rss_delete_file($forumto)) {
error('Could not purge the cached RSS feeds for the source and/or'.
'destination forum(s) - check your file permissionsforums', $return);
}
function forum_file_area_name($post) {
global $CFG;
- if (!isset($post->forum)) {
- debugging('missing forum', DEBUG_DEVELOPER);
+ if (!isset($post->forum) or !isset($post->course)) {
+ debugging('missing forum or course', DEBUG_DEVELOPER);
if (!$discussion = get_record('forum_discussions', 'id', $post->discussion)) {
return false;
}
if (!$forum = get_record('forum', 'id', $discussion->forum)) {
return false;
}
- $forumid = $forum->id;
+ $forumid = $forum->id;
+ $courseid = $forum->course;
} else {
- $forumid = $post->forum;
+ $forumid = $post->forum;
+ $courseid = $post->course;
}
- return "$post->course/$CFG->moddata/forum/$forumid/$post->id";
+ return "$courseid/$CFG->moddata/forum/$forumid/$post->id";
}
/**
global $USER, $CFG;
- $post->created = $post->modified = time();
- $post->mailed = "0";
- $post->userid = $USER->id;
+ $discussion = get_record('forum_discussions', 'id', $post->discussion);
+ $forum = get_record('forum', 'id', $discussion->forum);
+
+ $post->created = $post->modified = time();
+ $post->mailed = "0";
+ $post->userid = $USER->id;
$post->attachment = "";
+ $post->forum = $forum->id; // speedup
+ $post->course = $forum->course; // speedup
if (! $post->id = insert_record("forum_posts", $post)) {
return false;
*/
function forum_add_discussion($discussion,&$message) {
- GLOBAL $USER, $CFG;
+ global $USER, $CFG;
$timenow = time();
// The first post is stored as a real post, and linked
// to from the discuss entry.
+ $forum = get_record('forum', 'id', $discussion->forum);
+
$post = new object();
$post->discussion = 0;
$post->parent = 0;
$post->subject = $discussion->name;
$post->message = $discussion->intro;
$post->attachment = "";
- $post->forum = $discussion->forum;
- $post->course = $discussion->course;
+ $post->forum = $forum->id; // speedup
+ $post->course = $forum->course; // speedup
$post->format = $discussion->format;
$post->mailnow = $discussion->mailnow;