/** * */ function forum_delete_post($post, $children = false) { if ($childposts = get_records('forum_posts', 'parent', $post->id)) { if ($children) { foreach ($childposts as $childpost) { forum_delete_post($childpost, true); } } else { return false; } } if (delete_records("forum_posts", "id", $post->id)) { delete_records("forum_ratings", "post", $post->id); // Just in case forum_tp_delete_read_records(-1, $post->id); if ($post->attachment) { $discussion = get_record("forum_discussions", "id", $post->discussion); $post->course = $discussion->course; $post->forum = $discussion->forum; forum_delete_old_attachments($post); } // Just in case we are deleting the last post forum_discussion_update_last_post($post->discussion); return true; } return false; }
/** * This function is used by the remove_course_userdata function in moodlelib. * If this function exists, remove_course_userdata will execute it. * This function will remove all posts from the specified forum. */ function forum_delete_userdata($data, $showfeedback = true) { global $CFG; $sql = "DELETE FROM {$CFG->prefix}forum_posts\n WHERE discussion IN (\n SELECT fd.id FROM {$CFG->prefix}forum_discussions fd, {$CFG->prefix}forum f\n WHERE f.course={$data->courseid} AND f.id=fd.forum "; // closing ) added bellow $strreset = get_string('reset'); $attforumtype = ''; $postsarr = array(); if (!empty($data->reset_forum_news)) { $select = "{$sql} AND f.type = 'news' )"; $postsarr = forum_get_posts_with_attachments($data->courseid, " 'news' ", $postsarr); //select posts from news forum with attachments if (execute_sql($select, false) and $showfeedback) { notify($strreset . ': ' . get_string('namenews', 'forum'), 'notifysuccess'); } } if (!empty($data->reset_forum_single)) { $select = "{$sql} AND f.type = 'single' ) AND parent <> 0 "; $postsarr = forum_get_posts_with_attachments($data->courseid, " 'single' AND fp.parent<>0 ", $postsarr); if (execute_sql($select, false) and $showfeedback) { notify($strreset . ': ' . get_string('singleforum', 'forum'), 'notifysuccess'); } } if (!empty($data->reset_forum_eachuser)) { $select = "{$sql} AND f.type = 'eachuser' )"; $postsarr = forum_get_posts_with_attachments($data->courseid, " 'eachuser' ", $postsarr); if (execute_sql($select, false) and $showfeedback) { notify($strreset . ': ' . get_string('eachuserforum', 'forum'), 'notifysuccess'); } } if (!empty($data->reset_forum_general)) { $select = "{$sql} AND f.type = 'general' )"; $postsarr = forum_get_posts_with_attachments($data->courseid, " 'general' ", $postsarr); if (execute_sql($select, false) and $showfeedback) { notify($strreset . ': ' . get_string('generalforum', 'forum'), 'notifysuccess'); } } //selected posts with attachments to delete attachments files foreach ($postsarr as $post) { forum_delete_old_attachments($post); } if (!empty($data->reset_forum_subscriptions)) { $subscripsql = "DELETE FROM {$CFG->prefix}forum_subscriptions\n WHERE forum IN (\n SELECT id FROM {$CFG->prefix}forum\n WHERE course = {$data->courseid} )"; if (execute_sql($subscripsql, false) and $showfeedback) { notify($strreset . ': ' . get_string('resetsubscriptions', 'forum'), 'notifysuccess'); } } }