/** * Deletes a single anonforum 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 $anonforum Forum * @param bool $skipcompletion True to skip updating completion state if it * would otherwise be updated, i.e. when deleting entire anonforum anyway. * @return bool */ function anonforum_delete_post($post, $children, $course, $cm, $anonforum, $skipcompletion = false) { global $DB, $CFG; require_once $CFG->libdir . '/completionlib.php'; $context = context_module::instance($cm->id); if ($children !== 'ignore' && ($childposts = $DB->get_records('anonforum_posts', array('parent' => $post->id)))) { if ($children) { foreach ($childposts as $childpost) { anonforum_delete_post($childpost, true, $course, $cm, $anonforum, $skipcompletion); } } else { return false; } } // Delete ratings. require_once $CFG->dirroot . '/rating/lib.php'; $delopt = new stdClass(); $delopt->contextid = $context->id; $delopt->component = 'mod_anonforum'; $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_anonforum', 'attachment', $post->id); $fs->delete_area_files($context->id, 'mod_anonforum', 'post', $post->id); // Delete cached RSS feeds. if (!empty($CFG->enablerssfeeds)) { require_once $CFG->dirroot . '/mod/anonforum/rsslib.php'; anonforum_rss_delete_file($anonforum); } if ($DB->delete_records("anonforum_posts", array("id" => $post->id))) { anonforum_tp_delete_read_records(-1, $post->id); // Just in case we are deleting the last post anonforum_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 && ($anonforum->completiondiscussions || $anonforum->completionreplies || $anonforum->completionposts)) { $completion->update_state($cm, COMPLETION_INCOMPLETE, $post->userid); } } return true; } return false; }
require_capability('mod/anonforum:startdiscussion', context_module::instance($cmto->id)); if (!anonforum_move_attachments($discussion, $anonforum->id, $anonforumto->id)) { echo $OUTPUT->notification("Errors occurred while moving attachment directories - check your file permissions"); } $DB->set_field('anonforum_discussions', 'anonforum', $anonforumto->id, array('id' => $discussion->id)); $DB->set_field('anonforum_read', 'anonforumid', $anonforumto->id, array('discussionid' => $discussion->id)); $params = array('context' => $modcontext, 'objectid' => $discussion->id, 'anonymous' => 1, 'other' => array('fromanonforumid' => $anonforum->id, 'toanonforumid' => $anonforumto->id)); $event = \mod_anonforum\event\discussion_moved::create($params); $event->add_record_snapshot('anonforum_discussions', $discussion); $event->add_record_snapshot('anonforum', $anonforum); $event->add_record_snapshot('anonforum', $anonforumto); $event->trigger(); // Delete the RSS files for the 2 anonymous forums to force regeneration of the feeds require_once $CFG->dirroot . '/mod/anonforum/rsslib.php'; anonforum_rss_delete_file($anonforum); anonforum_rss_delete_file($anonforumto); redirect($return . '&moved=-1&sesskey=' . sesskey()); } if (empty($anonforum->anonymous)) { $params = array('context' => $modcontext, 'objectid' => $discussion->id, 'anonymous' => 1); $event = \mod_anonforum\event\discussion_viewed::create($params); $event->add_record_snapshot('anonforum_discussions', $discussion); $event->add_record_snapshot('anonforum', $anonforum); $event->trigger(); } unset($SESSION->fromdiscussion); if ($mode) { set_user_preference('anonforum_displaymode', $mode); } $displaymode = get_user_preferences('anonforum_displaymode', $CFG->anonforum_displaymode); if ($parent) {