if ($forumto->type == 'single') { print_error('cannotmovetosingleforum', 'forum', $return); } // Get target forum cm and check it is visible to current user. $modinfo = get_fast_modinfo($course); $forums = $modinfo->get_instances_of('forum'); if (!array_key_exists($forumto->id, $forums)) { print_error('cannotmovetonotfound', 'forum', $return); } $cmto = $forums[$forumto->id]; if (!$cmto->uservisible) { print_error('cannotmovenotvisible', 'forum', $return); } $destinationctx = context_module::instance($cmto->id); require_capability('mod/forum:startdiscussion', $destinationctx); if (!forum_move_attachments($discussion, $forum->id, $forumto->id)) { echo $OUTPUT->notification("Errors occurred while moving attachment directories - check your file permissions"); } $DB->set_field('forum_discussions', 'forum', $forumto->id, array('id' => $discussion->id)); $DB->set_field('forum_read', 'forumid', $forumto->id, array('discussionid' => $discussion->id)); $params = array('context' => $destinationctx, 'objectid' => $discussion->id, 'other' => array('fromforumid' => $forum->id, 'toforumid' => $forumto->id)); $event = \mod_forum\event\discussion_moved::create($params); $event->add_record_snapshot('forum_discussions', $discussion); $event->add_record_snapshot('forum', $forum); $event->add_record_snapshot('forum', $forumto); $event->trigger(); // Delete the RSS files for the 2 forums to force regeneration of the feeds require_once $CFG->dirroot . '/mod/forum/rsslib.php'; forum_rss_delete_file($forum); forum_rss_delete_file($forumto); redirect($return . '&moved=-1&sesskey=' . sesskey());
$canviewdiscussion = has_capability('mod/forum:viewdiscussion', $modcontext); if ($forum->type == "news") { if (!($USER->id == $discussion->userid || ($discussion->timestart == 0 || $discussion->timestart <= time()) && ($discussion->timeend == 0 || $discussion->timeend > time()))) { error('Discussion ID was incorrect or no longer exists', "{$CFG->wwwroot}/mod/forum/view.php?f={$forum->id}"); } } if (!empty($move)) { if (!($sourceforum = get_record('forum', 'id', $fromforum))) { error('Cannot find which forum this discussion is being moved from'); } if ($sourceforum->type == 'single') { error('Cannot move discussion from a simple single discussion forum'); } require_capability('mod/forum:movediscussions', $modcontext); 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; if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { add_to_log($course->id, "forum", "move discussion", "discuss.php?d={$discussion->id}", "{$discussion->id}", $cm->id); } else { add_to_log($course->id, "forum", "move discussion", "discuss.php?d={$discussion->id}", "{$discussion->id}"); } $discussionmoved = true; require_once 'rsslib.php'; require_once $CFG->libdir . '/rsslib.php'; // Delete the RSS files for the 2 forums because we want to force // the regeneration of the feeds since the discussions have been // moved.