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()); } $params = array('context' => $modcontext, 'objectid' => $discussion->id); $event = \mod_forum\event\discussion_viewed::create($params); $event->add_record_snapshot('forum_discussions', $discussion); $event->add_record_snapshot('forum', $forum); $event->trigger(); unset($SESSION->fromdiscussion); if ($mode) { set_user_preference('forum_displaymode', $mode); } $displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode); if ($parent) { // If flat AND parent, then force nested display this time if ($displaymode == FORUM_MODE_FLATOLDEST or $displaymode == FORUM_MODE_FLATNEWEST) {
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. if (!forum_rss_delete_file($forum) || !forum_rss_delete_file($sourceforum)) { notify('Could not purge the cached RSS feeds for the source and/or' . 'destination forum(s) - check your file permissionsforums'); } } else { error('You can\'t move to that forum - it doesn\'t exist!'); } } $logparameters = "d={$discussion->id}"; if ($parent) { $logparameters .= "&parent={$parent}"; } if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { add_to_log($course->id, "forum", "view discussion", "discuss.php?{$logparameters}", "{$discussion->id}", $cm->id); } else { add_to_log($course->id, "forum", "view discussion", "discuss.php?{$logparameters}", "{$discussion->id}"); }
/** * Deletes a single forum post. * * @global object * @param object $post Forum post object * @param mixed $children Whether to delete children. If false, returns false * if there are any children (without deleting the post). If true, * recursively deletes all children. If set to special value 'ignore', deletes * post regardless of children (this is for use only when deleting all posts * in a disussion). * @param object $course Course * @param object $cm Course-module * @param object $forum Forum * @param bool $skipcompletion True to skip updating completion state if it * would otherwise be updated, i.e. when deleting entire forum anyway. * @return bool */ function forum_delete_post($post, $children, $course, $cm, $forum, $skipcompletion = false) { global $DB, $CFG; require_once $CFG->libdir . '/completionlib.php'; $context = context_module::instance($cm->id); if ($children !== 'ignore' && ($childposts = $DB->get_records('forum_posts', array('parent' => $post->id)))) { if ($children) { foreach ($childposts as $childpost) { forum_delete_post($childpost, true, $course, $cm, $forum, $skipcompletion); } } else { return false; } } // Delete ratings. require_once $CFG->dirroot . '/rating/lib.php'; $delopt = new stdClass(); $delopt->contextid = $context->id; $delopt->component = 'mod_forum'; $delopt->ratingarea = 'post'; $delopt->itemid = $post->id; $rm = new rating_manager(); $rm->delete_ratings($delopt); // Delete attachments. $fs = get_file_storage(); $fs->delete_area_files($context->id, 'mod_forum', 'attachment', $post->id); $fs->delete_area_files($context->id, 'mod_forum', 'post', $post->id); // Delete cached RSS feeds. if (!empty($CFG->enablerssfeeds)) { require_once $CFG->dirroot . '/mod/forum/rsslib.php'; forum_rss_delete_file($forum); } if ($DB->delete_records("forum_posts", array("id" => $post->id))) { forum_tp_delete_read_records(-1, $post->id); // Just in case we are deleting the last post forum_discussion_update_last_post($post->discussion); // Update completion state if we are tracking completion based on number of posts // But don't bother when deleting whole thing if (!$skipcompletion) { $completion = new completion_info($course); if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && ($forum->completiondiscussions || $forum->completionreplies || $forum->completionposts)) { $completion->update_state($cm, COMPLETION_INCOMPLETE, $post->userid); } } return true; } return false; }
if (!coursemodule_visible_for_user($cmto)) { print_error('cannotmovenotvisible', 'forum', $return); } require_capability('mod/forum:startdiscussion', get_context_instance(CONTEXT_MODULE, $cmto->id)); 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)); add_to_log($course->id, 'forum', 'move discussion', "discuss.php?d={$discussion->id}", $discussion->id, $cmto->id); require_once $CFG->libdir . '/rsslib.php'; require_once '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. if (!forum_rss_delete_file($forum) || !forum_rss_delete_file($forumto)) { print_error('cannotpurgecachedrss', 'forum', $return); } redirect($return . '&moved=-1&sesskey=' . sesskey()); } $logparameters = "d={$discussion->id}"; if ($parent) { $logparameters .= "&parent={$parent}"; } add_to_log($course->id, 'forum', 'view discussion', "discuss.php?{$logparameters}", $discussion->id, $cm->id); unset($SESSION->fromdiscussion); if ($mode) { set_user_preference('forum_displaymode', $mode); } $displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode); if ($parent) {