From b8c55291ed7ed86565be2bc651bf20eb1a9ed4dd Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Thu, 17 Jun 2010 23:58:18 -0500 Subject: [feature/soft-delete] Lay the groundwork for a soft-delete feature So far, I've added no new functionality. The biggest change here is adjusting the DB column names to "visibility" rather than "approved". Some things here are pretty likely to change, for example the name and location of the topic_visibility class. Happy birthday phpBB :) PHPBB3-9657 --- phpBB/includes/functions_posting.php | 64 ++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index c50395a5df..2f51200b48 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -176,7 +176,7 @@ function update_post_information($type, $ids, $return_update_sql = false) if ($type != 'topic') { $topic_join = ', ' . TOPICS_TABLE . ' t'; - $topic_condition = 'AND t.topic_id = p.topic_id AND t.topic_approved = 1'; + $topic_condition = 'AND t.topic_id = p.topic_id AND t.topic_visibility = ' . ITEM_APPROVED; } else { @@ -190,7 +190,7 @@ function update_post_information($type, $ids, $return_update_sql = false) FROM ' . POSTS_TABLE . " p $topic_join WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . " $topic_condition - AND p.post_approved = 1"; + AND p.post_visibility = " . ITEM_APPROVED; } else { @@ -198,7 +198,7 @@ function update_post_information($type, $ids, $return_update_sql = false) FROM ' . POSTS_TABLE . " p $topic_join WHERE " . $db->sql_in_set('p.' . $type . '_id', $ids) . " $topic_condition - AND p.post_approved = 1 + AND p.post_visibility = " . ITEM_APPROVED . " GROUP BY p.{$type}_id"; } $result = $db->sql_query($sql); @@ -993,7 +993,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p' . " WHERE p.topic_id = $topic_id - " . ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND p.post_approved = 1' : '') . ' + AND " . topic_visibility::get_visibility_sql('post', $forum_id, 'p.') . ' ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . ' ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . ' ORDER BY p.post_time '; @@ -1489,7 +1489,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) delete_topics('topic_id', array($topic_id), false); $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1'; - $sql_data[FORUMS_TABLE] .= ($data['topic_approved']) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : ''; + $sql_data[FORUMS_TABLE] .= ($data['topic_visibility'] == ITEM_APPROVED) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : ''; $update_sql = update_post_information('forum', $forum_id, true); if (sizeof($update_sql)) @@ -1509,18 +1509,18 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; + $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : ''; $sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "', topic_time = " . (int) $row['post_time']; // Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply" - $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); + $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : ''); $next_post_id = (int) $row['post_id']; break; case 'delete_last_post': - $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; + $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : ''; $update_sql = update_post_information('forum', $forum_id, true); if (sizeof($update_sql)) @@ -1529,7 +1529,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); } - $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); + $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : ''); $update_sql = update_post_information('topic', $topic_id, true); if (sizeof($update_sql)) @@ -1541,8 +1541,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) { $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . " - WHERE topic_id = $topic_id " . - ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : ''); + WHERE topic_id = $topic_id + AND " . topic_visibility::get_visibility_sql('post', $forum_id); $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1554,17 +1554,17 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) case 'delete': $sql = 'SELECT post_id FROM ' . POSTS_TABLE . " - WHERE topic_id = $topic_id " . - ((!$auth->acl_get('m_approve', $forum_id)) ? 'AND post_approved = 1' : '') . ' + WHERE topic_id = $topic_id + AND " . topic_visibility::get_visibility_sql('post', $forum_id) . ' AND post_time > ' . $data['post_time'] . ' ORDER BY post_time ASC'; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - $sql_data[FORUMS_TABLE] = ($data['post_approved']) ? 'forum_posts = forum_posts - 1' : ''; + $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : ''; - $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_approved']) ? ', topic_replies = topic_replies - 1' : ''); + $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : ''); $next_post_id = (int) $row['post_id']; break; } @@ -1674,9 +1674,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $poster_id = ($mode == 'edit') ? $data['poster_id'] : (int) $user->data['user_id']; // Retrieve some additional information if not present - if ($mode == 'edit' && (!isset($data['post_approved']) || !isset($data['topic_approved']) || $data['post_approved'] === false || $data['topic_approved'] === false)) + if ($mode == 'edit' && (!isset($data['post_visibility']) || !isset($data['topic_visibility']) || $data['post_visibility'] === false || $data['topic_visibility'] === false)) { - $sql = 'SELECT p.post_approved, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_approved + $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_visibility FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE t.topic_id = p.topic_id AND p.post_id = ' . $data['post_id']; @@ -1684,8 +1684,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $topic_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - $data['topic_approved'] = $topic_row['topic_approved']; - $data['post_approved'] = $topic_row['post_approved']; + $data['topic_visibility'] = $topic_row['topic_visibility']; + $data['post_visibility'] = $topic_row['post_visibility']; } // This variable indicates if the user is able to post or put into the queue - it is used later for all code decisions regarding approval @@ -1719,7 +1719,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'icon_id' => $data['icon_id'], 'poster_ip' => $user->ip, 'post_time' => $current_time, - 'post_approved' => $post_approval, + 'post_visibility' => $post_approval, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], @@ -1785,7 +1785,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'forum_id' => $data['forum_id'], 'poster_id' => $data['poster_id'], 'icon_id' => $data['icon_id'], - 'post_approved' => (!$post_approval) ? 0 : $data['post_approved'], + 'post_visibility' => (!$post_approval) ? 0 : $data['post_visibility'], 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], @@ -1807,7 +1807,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u break; } - $post_approved = $sql_data[POSTS_TABLE]['sql']['post_approved']; + $post_approved = $sql_data[POSTS_TABLE]['sql']['post_visibility']; $topic_row = array(); // And the topic ladies and gentlemen @@ -1820,7 +1820,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_last_view_time' => $current_time, 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], - 'topic_approved' => $post_approval, + 'topic_visibility' => $post_approval, 'topic_title' => $subject, 'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), 'topic_first_poster_colour' => $user->data['user_colour'], @@ -1897,7 +1897,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $sql_data[TOPICS_TABLE]['sql'] = array( 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], - 'topic_approved' => (!$post_approval) ? 0 : $data['topic_approved'], + 'topic_visibility' => (!$post_approval) ? 0 : $data['topic_visibility'], 'topic_title' => $subject, 'topic_first_poster_name' => $username, 'topic_type' => $topic_type, @@ -1913,12 +1913,12 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u ); // Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved - if (!$post_approval && $data['topic_approved']) + if (!$post_approval && $data['topic_visibility'] == ITEM_APPROVED) { // Do we need to grab some topic informations? if (!sizeof($topic_row)) { - $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_approved + $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_visibility FROM ' . TOPICS_TABLE . ' WHERE topic_id = ' . $data['topic_id']; $result = $db->sql_query($sql); @@ -1949,7 +1949,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'edit_last_post': // Correctly set back the topic replies and forum posts... but only if the post was approved before. - if (!$post_approval && $data['post_approved']) + if (!$post_approval && $data['post_visibility'] == ITEM_APPROVED) { $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1'; @@ -2173,7 +2173,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // we need to update the last forum information // only applicable if the topic is approved - if ($post_approved || !$data['post_approved']) + if ($post_approved || $data['post_visibility'] != ITEM_APPROVED) { // the last post makes us update the forum table. This can happen if... // We make a new topic @@ -2219,13 +2219,13 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'"; } } - else if ($data['post_approved'] !== $post_approved) + else if ($data['post_visibility'] !== $post_approved) { // we need a fresh change of socks, everything has become invalidated $sql = 'SELECT MAX(topic_last_post_id) as last_post_id FROM ' . TOPICS_TABLE . ' WHERE forum_id = ' . (int) $data['forum_id'] . ' - AND topic_approved = 1'; + AND topic_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -2290,13 +2290,13 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } } } - else if (!$data['post_approved'] && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) + else if (!$data['post_visibility'] == ITEM_APPROVED && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) { // like having the rug pulled from under us $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . (int) $data['topic_id'] . ' - AND post_approved = 1'; + AND post_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); -- cgit v1.2.1 From c32d76080605f843bb23e9a608c368d4b5dc55d8 Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Sun, 20 Jun 2010 15:01:26 -0500 Subject: [feature/soft-delete] I told you I was going to rename the class! Rename topic_visibility class to phpbb_visibility. Also a bit of work to the class itself, mostly cleanup and adding the comments that I'd previously written. PHPBB3-9657 --- phpBB/includes/functions_posting.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 2f51200b48..12448ea0ce 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -993,7 +993,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p' . " WHERE p.topic_id = $topic_id - AND " . topic_visibility::get_visibility_sql('post', $forum_id, 'p.') . ' + AND " . phpbb_visibility::get_visibility_sql('post', $forum_id, 'p.') . ' ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . ' ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . ' ORDER BY p.post_time '; @@ -1542,7 +1542,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . topic_visibility::get_visibility_sql('post', $forum_id); + AND " . phpbb_visibility::get_visibility_sql('post', $forum_id); $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1555,7 +1555,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) $sql = 'SELECT post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . topic_visibility::get_visibility_sql('post', $forum_id) . ' + AND " . phpbb_visibility::get_visibility_sql('post', $forum_id) . ' AND post_time > ' . $data['post_time'] . ' ORDER BY post_time ASC'; $result = $db->sql_query_limit($sql, 1); -- cgit v1.2.1 From fb13ab83e476d2afbc7bb181f7ab90df98f996da Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Sun, 27 Jun 2010 14:22:36 -0500 Subject: [feature/soft-delete] Implement the ability to soft-delete and restore posts The soft delete feature seems to work. Tests are pending. A real icon is pending. Add the permissions and the interface to soft-delete posts. Also able to restore posts via the MCP queue PHPBB3-9657 --- phpBB/includes/functions_posting.php | 112 +++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 50 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 12448ea0ce..b264e35a93 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1411,7 +1411,7 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id /** * Delete Post */ -function delete_post($forum_id, $topic_id, $post_id, &$data) +function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) { global $db, $user, $auth; global $config, $phpEx, $phpbb_root_path; @@ -1422,10 +1422,14 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) { $post_mode = 'delete_topic'; } - else if ($data['topic_first_post_id'] == $post_id) + else if ($data['topic_first_post_id'] == $post_id && !$is_soft) { $post_mode = 'delete_first_post'; } + else if ($data['topic_first_post_id'] == $post_id && $is_soft) + { + $post_mode = 'delete_topic'; + } else if ($data['topic_last_post_id'] == $post_id) { $post_mode = 'delete_last_post'; @@ -1460,14 +1464,22 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) $db->sql_freeresult($result); } - if (!delete_posts('post_id', array($post_id), false, false)) + if ($is_soft) + { + phpbb_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); + phpbb_visibility::hide_post($forum_id, time(), $sql_data); + } + else { - // Try to delete topic, we may had an previous error causing inconsistency - if ($post_mode == 'delete_topic') + if (!delete_posts('post_id', array($post_id), false, false)) { - delete_topics('topic_id', array($topic_id), false); + // Try to delete topic, we may had an previous error causing inconsistency + if ($post_mode == 'delete_topic') + { + delete_topics('topic_id', array($topic_id), false); + } + trigger_error('ALREADY_DELETED'); } - trigger_error('ALREADY_DELETED'); } $db->sql_transaction('commit'); @@ -1486,17 +1498,31 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) update_post_information('forum', $updated_forum); } - delete_topics('topic_id', array($topic_id), false); + if ($is_soft) + { + $topic_row = array(); + phpbb_visibility::set_topic_visibility(POST_DELETED, $topic_id, $forum_id); + phpbb_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data); + } + else + { + delete_topics('topic_id', array($topic_id), false); - $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1'; - $sql_data[FORUMS_TABLE] .= ($data['topic_visibility'] == ITEM_APPROVED) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : ''; - $update_sql = update_post_information('forum', $forum_id, true); - if (sizeof($update_sql)) - { - $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; - $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); + if ($data['topic_type'] != POST_GLOBAL) + { + $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1'; + $sql_data[FORUMS_TABLE] .= ($data['topic_visibility'] == ITEM_APPROVED) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : ''; + } + + $update_sql = update_post_information('forum', $forum_id, true); + if (sizeof($update_sql)) + { + $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; + $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); + } } + break; case 'delete_first_post': @@ -1520,19 +1546,27 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) break; case 'delete_last_post': - $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : ''; - - $update_sql = update_post_information('forum', $forum_id, true); - if (sizeof($update_sql)) + if ($is_soft) { - $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; - $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); + phpbb_visibility::hide_post($forum_id, time(), $sql_data); + phpbb_visibility::set_post_visibility($post_id, $topic_id, $forum_id, false, true); } + else + { + $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : ''; + + $update_sql = update_post_information('forum', $forum_id, true); + if (sizeof($update_sql)) + { + $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; + $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); + } - $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : ''); + $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : ''); + } $update_sql = update_post_information('topic', $topic_id, true); - if (sizeof($update_sql)) + if (sizeof($update_sql) && !$is_soft) { $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]); $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]); @@ -1702,7 +1736,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Mods are able to force approved/unapproved posts. True means the post is approved, false the post is unapproved if (isset($data['force_approved_state'])) { - $post_approval = ($data['force_approved_state']) ? 1 : 0; + $post_approval = ($data['force_approved_state']) ? ITEM_APPROVED : ITEM_UNAPPROVED; } // Start the transaction here @@ -1915,32 +1949,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved if (!$post_approval && $data['topic_visibility'] == ITEM_APPROVED) { - // Do we need to grab some topic informations? - if (!sizeof($topic_row)) - { - $sql = 'SELECT topic_type, topic_replies, topic_replies_real, topic_visibility - FROM ' . TOPICS_TABLE . ' - WHERE topic_id = ' . $data['topic_id']; - $result = $db->sql_query($sql); - $topic_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - } - - // If this is the only post remaining we do not need to decrement topic_replies. - // Also do not decrement if first post - then the topic_replies will not be adjusted if approving the topic again. - - // If this is an edited topic or the first post the topic gets completely disapproved later on... - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics = forum_topics - 1'; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - ' . ($topic_row['topic_replies'] + 1); - - set_config_count('num_topics', -1, true); - set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-1), true); - - // Only decrement this post, since this is the one non-approved now - if ($auth->acl_get('f_postcount', $data['forum_id'])) - { - $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1'; - } + phpbb_visibility::hide_topic($data['topic_id'], $data['forum_id'], $topic_row, $sql_data); } break; @@ -1951,6 +1960,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Correctly set back the topic replies and forum posts... but only if the post was approved before. if (!$post_approval && $data['post_visibility'] == ITEM_APPROVED) { + //phpbb_visibility::hide_post($forum_id, $current_time, $sql_data); + // ^^ hide_post SQL is identical, except that it does not include the ['stat'] sub-array $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1'; @@ -1960,6 +1971,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1'; } + } break; -- cgit v1.2.1 From a80cfafdd91a384ba810a8ee0d43406bba955faa Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Wed, 30 Jun 2010 13:38:49 -0500 Subject: [feature/soft-delete] Rename phpbb_visibility class to phpbb_content_visibility Rename the class to more accurately reflect what it does. PHPBB3-9657 --- phpBB/includes/functions_posting.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index b264e35a93..364a3e7fe2 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -993,7 +993,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p' . " WHERE p.topic_id = $topic_id - AND " . phpbb_visibility::get_visibility_sql('post', $forum_id, 'p.') . ' + AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.') . ' ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . ' ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . ' ORDER BY p.post_time '; @@ -1466,8 +1466,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) if ($is_soft) { - phpbb_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); - phpbb_visibility::hide_post($forum_id, time(), $sql_data); + phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); + phpbb_content_visibility::hide_post($forum_id, time(), $sql_data); } else { @@ -1501,8 +1501,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) if ($is_soft) { $topic_row = array(); - phpbb_visibility::set_topic_visibility(POST_DELETED, $topic_id, $forum_id); - phpbb_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data); + phpbb_content_visibility::set_topic_visibility(POST_DELETED, $topic_id, $forum_id); + phpbb_content_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data); } else { @@ -1548,8 +1548,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) case 'delete_last_post': if ($is_soft) { - phpbb_visibility::hide_post($forum_id, time(), $sql_data); - phpbb_visibility::set_post_visibility($post_id, $topic_id, $forum_id, false, true); + phpbb_content_visibility::hide_post($forum_id, time(), $sql_data); + phpbb_content_visibility::set_post_visibility($post_id, $topic_id, $forum_id, false, true); } else { @@ -1576,7 +1576,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . phpbb_visibility::get_visibility_sql('post', $forum_id); + AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id); $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -1589,7 +1589,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) $sql = 'SELECT post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . phpbb_visibility::get_visibility_sql('post', $forum_id) . ' + AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id) . ' AND post_time > ' . $data['post_time'] . ' ORDER BY post_time ASC'; $result = $db->sql_query_limit($sql, 1); @@ -1949,7 +1949,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved if (!$post_approval && $data['topic_visibility'] == ITEM_APPROVED) { - phpbb_visibility::hide_topic($data['topic_id'], $data['forum_id'], $topic_row, $sql_data); + phpbb_content_visibility::hide_topic($data['topic_id'], $data['forum_id'], $topic_row, $sql_data); } break; @@ -1960,7 +1960,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Correctly set back the topic replies and forum posts... but only if the post was approved before. if (!$post_approval && $data['post_visibility'] == ITEM_APPROVED) { - //phpbb_visibility::hide_post($forum_id, $current_time, $sql_data); + //phpbb_content_visibility::hide_post($forum_id, $current_time, $sql_data); // ^^ hide_post SQL is identical, except that it does not include the ['stat'] sub-array $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1'; -- cgit v1.2.1 From 1ab41f8dc6ec81f2aaf152229d5f0275de796c85 Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Sat, 17 Jul 2010 14:34:36 -0500 Subject: [feature/soft-delete] Fix some small bugs To wit: using non-existing constant POST_DELETED in posting.php; first test post was initially unapproved; soft delete checkbox appeared at post time Links pointing to the wrong place. PHPBB3-9657 --- phpBB/includes/functions_posting.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 364a3e7fe2..b63a41df7d 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1467,7 +1467,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) if ($is_soft) { phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); - phpbb_content_visibility::hide_post($forum_id, time(), $sql_data); + phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data); } else { @@ -1501,7 +1501,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) if ($is_soft) { $topic_row = array(); - phpbb_content_visibility::set_topic_visibility(POST_DELETED, $topic_id, $forum_id); + phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id); phpbb_content_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data); } else @@ -1548,8 +1548,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) case 'delete_last_post': if ($is_soft) { - phpbb_content_visibility::hide_post($forum_id, time(), $sql_data); - phpbb_content_visibility::set_post_visibility($post_id, $topic_id, $forum_id, false, true); + phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data); + phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, false, true); } else { -- cgit v1.2.1 From e5377e98c7eca8754f423ef495e4b092590f4e03 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 28 Sep 2012 16:53:38 +0200 Subject: [feature/soft-delete] Allow setting the visibility change reason PHPBB3-9657 --- phpBB/includes/functions_posting.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index b63a41df7d..38f173330a 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1411,7 +1411,7 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id /** * Delete Post */ -function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) +function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $softdelete_reason = '') { global $db, $user, $auth; global $config, $phpEx, $phpbb_root_path; @@ -1466,7 +1466,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) if ($is_soft) { - phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); + phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data); } else @@ -1501,7 +1501,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) if ($is_soft) { $topic_row = array(); - phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id); + phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason); phpbb_content_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data); } else @@ -1548,8 +1548,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false) case 'delete_last_post': if ($is_soft) { + phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, false, true); phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data); - phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, false, true); } else { -- cgit v1.2.1 From 009bd698fb46a529f09d9d9a63748e63eec62895 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 6 Oct 2012 03:59:49 +0200 Subject: [feature/soft-delete] Update and simplify the logic on delete_post() Todo: delete_topic case PHPBB3-9567 --- phpBB/includes/functions_posting.php | 80 +++++++++++++++++------------------- 1 file changed, 38 insertions(+), 42 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 38f173330a..7738fcbc4e 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1422,14 +1422,10 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { $post_mode = 'delete_topic'; } - else if ($data['topic_first_post_id'] == $post_id && !$is_soft) + else if ($data['topic_first_post_id'] == $post_id) { $post_mode = 'delete_first_post'; } - else if ($data['topic_first_post_id'] == $post_id && $is_soft) - { - $post_mode = 'delete_topic'; - } else if ($data['topic_last_post_id'] == $post_id) { $post_mode = 'delete_last_post'; @@ -1464,10 +1460,10 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $db->sql_freeresult($result); } + // (Soft) delete the post if ($is_soft) { phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); - phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data); } else { @@ -1535,53 +1531,45 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); - $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : ''; - - $sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . (($row['poster_id'] == ANONYMOUS) ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "', topic_time = " . (int) $row['post_time']; - - // Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply" - $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : ''); - $next_post_id = (int) $row['post_id']; + + $sql_data[TOPICS_TABLE] = $db->sql_build_array('UPDATE', array( + 'topic_poster' => (int) $row['poster_id'], + 'topic_first_post_id' => (int) $row['post_id'] + 'topic_first_poster_colour' => $row['user_colour'], + 'topic_first_poster_name' => ($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username'], + 'topic_time' => (int) $row['post_time'], + )); break; case 'delete_last_post': - if ($is_soft) + if (!$is_soft) { - phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, false, true); - phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data); - } - else - { - $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : ''; - $update_sql = update_post_information('forum', $forum_id, true); if (sizeof($update_sql)) { - $sql_data[FORUMS_TABLE] .= ($sql_data[FORUMS_TABLE]) ? ', ' : ''; - $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]); + $sql_data[FORUMS_TABLE] = ($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . implode(', ', $update_sql[$forum_id]); } - $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : ''); - } + $sql_data[TOPICS_TABLE] = ($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_bumped = 0, topic_bumper = 0'; - $update_sql = update_post_information('topic', $topic_id, true); - if (sizeof($update_sql) && !$is_soft) - { - $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]); - $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]); + $update_sql = update_post_information('topic', $topic_id, true); + if (!empty($update_sql)) + { + $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]); + $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]); + } } - else + + if (!$next_post_id) { $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id); $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); + $next_post_id = (int) $db->sql_fetchfield('last_post_id'); $db->sql_freeresult($result); - - $next_post_id = (int) $row['last_post_id']; } break; @@ -1593,14 +1581,22 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ AND post_time > ' . $data['post_time'] . ' ORDER BY post_time ASC'; $result = $db->sql_query_limit($sql, 1); - $row = $db->sql_fetchrow($result); + $next_post_id = (int) $db->sql_fetchfield('post_id'); $db->sql_freeresult($result); + break; + } - $sql_data[FORUMS_TABLE] = ($data['post_visibility'] == ITEM_APPROVED) ? 'forum_posts = forum_posts - 1' : ''; + if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) + { + if ($data['post_visibility'] == ITEM_APPROVED) + { + phpbb_content_visibility::remove_post_from_postcount($forum_id, $data, $sql_data); + } - $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . (($data['post_visibility'] == ITEM_APPROVED) ? ', topic_replies = topic_replies - 1' : ''); - $next_post_id = (int) $row['post_id']; - break; + if (!$is_soft) + { + $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1'; + } } if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) @@ -1625,7 +1621,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $where_sql = array( FORUMS_TABLE => "forum_id = $forum_id", TOPICS_TABLE => "topic_id = $topic_id", - USERS_TABLE => 'user_id = ' . $data['poster_id'] + USERS_TABLE => 'user_id = ' . $data['poster_id'], ); foreach ($sql_data as $table => $update_sql) @@ -1960,7 +1956,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Correctly set back the topic replies and forum posts... but only if the post was approved before. if (!$post_approval && $data['post_visibility'] == ITEM_APPROVED) { - //phpbb_content_visibility::hide_post($forum_id, $current_time, $sql_data); + //phpbb_content_visibility::remove_post_from_postcount($forum_id, $current_time, $sql_data); // ^^ hide_post SQL is identical, except that it does not include the ['stat'] sub-array $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1'; @@ -2302,7 +2298,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } } } - else if (!$data['post_visibility'] == ITEM_APPROVED && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) + else if ($data['post_visibility'] != ITEM_APPROVED && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) { // like having the rug pulled from under us $sql = 'SELECT MAX(post_id) as last_post_id -- cgit v1.2.1 From 44005f338e227c10a21270456d181d56749d3f29 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 6 Oct 2012 16:36:38 +0200 Subject: [feature/soft-delete] Fix delete_post() function PHPBB3-9567 --- phpBB/includes/functions_posting.php | 48 ++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 16 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 7738fcbc4e..d9fbd84ce1 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1490,7 +1490,11 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { // counting is fun! we only have to do sizeof($forum_ids) number of queries, // even if the topic is moved back to where its shadow lives (we count how many times it is in a forum) - $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_topics_real = forum_topics_real - ' . $topic_count . ', forum_topics = forum_topics - ' . $topic_count . ' WHERE forum_id = ' . $updated_forum); + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET forum_topics_real = forum_topics_real - ' . $topic_count . ', + forum_topics = forum_topics - ' . $topic_count . ' + WHERE forum_id = ' . $updated_forum; + $db->sql_query($sql); update_post_information('forum', $updated_forum); } @@ -1498,18 +1502,15 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { $topic_row = array(); phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason); - phpbb_content_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data); + phpbb_content_visibility::remove_topic_from_statistic($topic_id, $forum_id, $topic_row, $sql_data); } else { delete_topics('topic_id', array($topic_id), false); - if ($data['topic_type'] != POST_GLOBAL) - { - $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1'; - $sql_data[FORUMS_TABLE] .= ($data['topic_visibility'] == ITEM_APPROVED) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : ''; - } + $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1'; + $sql_data[FORUMS_TABLE] .= ($data['topic_visibility'] == ITEM_APPROVED) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : ''; $update_sql = update_post_information('forum', $forum_id, true); if (sizeof($update_sql)) @@ -1526,16 +1527,30 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u WHERE p.topic_id = $topic_id AND p.poster_id = u.user_id - ORDER BY p.post_time ASC"; + AND p.post_visibility = " . ITEM_APPROVED . ' + ORDER BY p.post_time ASC'; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); + if (!$row) + { + // No approved post, so the first is a not-approved post (unapproved or soft deleted) + $sql = 'SELECT p.post_id, p.poster_id, p.post_time, p.post_username, u.username, u.user_colour + FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u + WHERE p.topic_id = $topic_id + AND p.poster_id = u.user_id + ORDER BY p.post_time ASC"; + $result = $db->sql_query_limit($sql, 1); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + } + $next_post_id = (int) $row['post_id']; $sql_data[TOPICS_TABLE] = $db->sql_build_array('UPDATE', array( 'topic_poster' => (int) $row['poster_id'], - 'topic_first_post_id' => (int) $row['post_id'] + 'topic_first_post_id' => (int) $row['post_id'], 'topic_first_poster_colour' => $row['user_colour'], 'topic_first_poster_name' => ($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username'], 'topic_time' => (int) $row['post_time'], @@ -1545,13 +1560,14 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ case 'delete_last_post': if (!$is_soft) { + // Update last post information when hard deleting. Soft delete already did that by itself. $update_sql = update_post_information('forum', $forum_id, true); if (sizeof($update_sql)) { - $sql_data[FORUMS_TABLE] = ($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . implode(', ', $update_sql[$forum_id]); + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . implode(', ', $update_sql[$forum_id]); } - $sql_data[TOPICS_TABLE] = ($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_bumped = 0, topic_bumper = 0'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_bumped = 0, topic_bumper = 0'; $update_sql = update_post_information('topic', $topic_id, true); if (!empty($update_sql)) @@ -1586,11 +1602,11 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ break; } - if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) + if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post' && !$is_soft)) { if ($data['post_visibility'] == ITEM_APPROVED) { - phpbb_content_visibility::remove_post_from_postcount($forum_id, $data, $sql_data); + phpbb_content_visibility::remove_post_from_statistic($forum_id, $data, $sql_data); } if (!$is_soft) @@ -1945,7 +1961,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved if (!$post_approval && $data['topic_visibility'] == ITEM_APPROVED) { - phpbb_content_visibility::hide_topic($data['topic_id'], $data['forum_id'], $topic_row, $sql_data); + phpbb_content_visibility::remove_topic_from_statistic($data['topic_id'], $data['forum_id'], $topic_row, $sql_data); } break; @@ -1956,8 +1972,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Correctly set back the topic replies and forum posts... but only if the post was approved before. if (!$post_approval && $data['post_visibility'] == ITEM_APPROVED) { - //phpbb_content_visibility::remove_post_from_postcount($forum_id, $current_time, $sql_data); - // ^^ hide_post SQL is identical, except that it does not include the ['stat'] sub-array + //phpbb_content_visibility::remove_post_from_statistic($forum_id, $current_time, $sql_data); + // ^^ remove_post_from_statistic SQL is identical, except that it does not include the ['stat'] sub-array $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1'; -- cgit v1.2.1 From 25804eb8e8b17196116e233b2c8ad3b444cfb5ae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 6 Oct 2012 19:56:52 +0200 Subject: [feature/soft-delete] Add test case for (soft)deleting the only post + fix PHPBB3-9567 --- phpBB/includes/functions_posting.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index d9fbd84ce1..9cf7b59ad3 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1461,11 +1461,11 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ } // (Soft) delete the post - if ($is_soft) + if ($is_soft && ($post_mode != 'delete_topic')) { phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); } - else + else if (!$is_soft) { if (!delete_posts('post_id', array($post_id), false, false)) { @@ -1502,7 +1502,6 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { $topic_row = array(); phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason); - phpbb_content_visibility::remove_topic_from_statistic($topic_id, $forum_id, $topic_row, $sql_data); } else { -- cgit v1.2.1 From c525e900d3b96b829c939010db343d8032698011 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 8 Oct 2012 15:01:20 +0200 Subject: [feature/soft-delete] Allow to update multiple posts with set_post_visibility PHPBB3-9567 --- phpBB/includes/functions_posting.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 9cf7b59ad3..2ae4fe2bd8 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1629,8 +1629,6 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ } } -// $sql_data[USERS_TABLE] = ($data['post_postcount']) ? 'user_posts = user_posts - 1' : ''; - $db->sql_transaction('begin'); $where_sql = array( -- cgit v1.2.1 From 53e01bba19784b0fb36324c10c010f969f05d253 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 8 Oct 2012 22:47:50 +0200 Subject: [feature/soft-delete] Update post counts within set_post_visibility This is an additional query in some rare cases, but it makes it much easier to use and understand. This is mostly a preparation for the restore case. PHPBB3-9567 --- phpBB/includes/functions_posting.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 2ae4fe2bd8..250d20b005 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1601,21 +1601,19 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ break; } - if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post' && !$is_soft)) - { - if ($data['post_visibility'] == ITEM_APPROVED) - { - phpbb_content_visibility::remove_post_from_statistic($forum_id, $data, $sql_data); - } + if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) + { if (!$is_soft) { - $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1'; + if ($data['post_visibility'] == ITEM_APPROVED) + { + phpbb_content_visibility::remove_post_from_statistic($data, $sql_data); + } + + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_replies_real = topic_replies_real - 1'; } - } - if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) - { $sql = 'SELECT 1 AS has_attachments FROM ' . ATTACHMENTS_TABLE . ' WHERE topic_id = ' . $topic_id; @@ -1625,7 +1623,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ if (!$has_attachments) { - $sql_data[TOPICS_TABLE] .= ', topic_attachment = 0'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_attachment = 0'; } } @@ -1969,7 +1967,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Correctly set back the topic replies and forum posts... but only if the post was approved before. if (!$post_approval && $data['post_visibility'] == ITEM_APPROVED) { - //phpbb_content_visibility::remove_post_from_statistic($forum_id, $current_time, $sql_data); + //phpbb_content_visibility::remove_post_from_statistic($current_time, $sql_data); // ^^ remove_post_from_statistic SQL is identical, except that it does not include the ['stat'] sub-array $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1'; -- cgit v1.2.1 From e447a0fa0797440688335bc0dc18c8a73b5586ec Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 8 Oct 2012 23:09:12 +0200 Subject: [feature/soft-delete] Fix restoring a post via editing PHPBB3-9567 --- phpBB/includes/functions_posting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 250d20b005..6d74c6b2d7 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1481,7 +1481,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $db->sql_transaction('commit'); // Collect the necessary information for updating the tables - $sql_data[FORUMS_TABLE] = ''; + $sql_data[FORUMS_TABLE] = $sql_data[TOPICS_TABLE] = ''; switch ($post_mode) { case 'delete_topic': -- cgit v1.2.1 From e4c9e55b53923baedfc9318eb589a914a4ffccef Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 9 Oct 2012 22:24:06 +0200 Subject: [feature/soft-delete] Fix several issues within submit_post() - $post_visibility is not boolean, so we need to check for == ITEM_APPROVED - sync() already updates the topic/forum info, so we don't need to do that again - use set_post_visibility() when changing the posts visibility Should be ready for testing. PHPBB3-9567 --- phpBB/includes/functions_posting.php | 291 +++++++++++------------------------ 1 file changed, 91 insertions(+), 200 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6d74c6b2d7..b6223b72d4 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1729,21 +1729,24 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $data['post_visibility'] = $topic_row['post_visibility']; } - // This variable indicates if the user is able to post or put into the queue - it is used later for all code decisions regarding approval - // The variable name should be $post_approved, because it indicates if the post is approved or not - $post_approval = 1; + // This variable indicates if the user is able to post or put into the queue + $post_visibility = ITEM_APPROVED; // Check the permissions for post approval. Moderators are not affected. if (!$auth->acl_get('f_noapprove', $data['forum_id']) && !$auth->acl_get('m_approve', $data['forum_id'])) { // Post not approved, but in queue - $post_approval = 0; + $post_visibility = ITEM_UNAPPROVED; } - // Mods are able to force approved/unapproved posts. True means the post is approved, false the post is unapproved + // MODs/Extensions are able to force any visibility on posts if (isset($data['force_approved_state'])) { - $post_approval = ($data['force_approved_state']) ? ITEM_APPROVED : ITEM_UNAPPROVED; + $post_visibility = (in_array((int) $data['force_approved_state'], array(ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED))) ? (int) $data['force_approved_state'] : $post_visibility; + } + if (isset($data['force_visibility'])) + { + $post_visibility = (in_array((int) $data['force_visibility'], array(ITEM_APPROVED, ITEM_UNAPPROVED, ITEM_DELETED))) ? (int) $data['force_visibility'] : $post_visibility; } // Start the transaction here @@ -1760,7 +1763,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'icon_id' => $data['icon_id'], 'poster_ip' => $user->ip, 'post_time' => $current_time, - 'post_visibility' => $post_approval, + 'post_visibility' => $post_visibility, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], @@ -1826,7 +1829,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'forum_id' => $data['forum_id'], 'poster_id' => $data['poster_id'], 'icon_id' => $data['icon_id'], - 'post_visibility' => (!$post_approval) ? 0 : $data['post_visibility'], + // We will change the visibility later + //'post_visibility' => $post_visibility, 'enable_bbcode' => $data['enable_bbcode'], 'enable_smilies' => $data['enable_smilies'], 'enable_magic_url' => $data['enable_urls'], @@ -1847,8 +1851,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u break; } - - $post_approved = $sql_data[POSTS_TABLE]['sql']['post_visibility']; $topic_row = array(); // And the topic ladies and gentlemen @@ -1861,7 +1863,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_last_view_time' => $current_time, 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], - 'topic_visibility' => $post_approval, + 'topic_visibility' => $post_visibility, 'topic_title' => $subject, 'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), 'topic_first_poster_colour' => $user->data['user_colour'], @@ -1893,13 +1895,13 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u ); } - $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : ''); + $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_visibility == ITEM_APPROVED) ? ', user_posts = user_posts + 1' : ''); - if ($post_approval) + if ($post_visibility == ITEM_APPROVED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; } - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($post_approval) ? ', forum_topics = forum_topics + 1' : ''); + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($post_visibility == ITEM_APPROVED) ? ', forum_topics = forum_topics + 1' : ''); break; case 'reply': @@ -1907,12 +1909,12 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . - (($post_approval) ? ', topic_replies = topic_replies + 1' : '') . + (($post_visibility == ITEM_APPROVED) ? ', topic_replies = topic_replies + 1' : '') . ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : ''); - $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_approval) ? ', user_posts = user_posts + 1' : ''); + $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_visibility == ITEM_APPROVED) ? ', user_posts = user_posts + 1' : ''); - if ($post_approval) + if ($post_visibility == ITEM_APPROVED) { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; } @@ -1938,7 +1940,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $sql_data[TOPICS_TABLE]['sql'] = array( 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], - 'topic_visibility' => (!$post_approval) ? 0 : $data['topic_visibility'], 'topic_title' => $subject, 'topic_first_poster_name' => $username, 'topic_type' => $topic_type, @@ -1953,34 +1954,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_attachment' => (!empty($data['attachment_data'])) ? 1 : (isset($data['topic_attachment']) ? $data['topic_attachment'] : 0), ); - // Correctly set back the topic replies and forum posts... only if the topic was approved before and now gets disapproved - if (!$post_approval && $data['topic_visibility'] == ITEM_APPROVED) - { - phpbb_content_visibility::remove_topic_from_statistic($data['topic_id'], $data['forum_id'], $topic_row, $sql_data); - } - - break; - - case 'edit': - case 'edit_last_post': - - // Correctly set back the topic replies and forum posts... but only if the post was approved before. - if (!$post_approval && $data['post_visibility'] == ITEM_APPROVED) - { - //phpbb_content_visibility::remove_post_from_statistic($current_time, $sql_data); - // ^^ remove_post_from_statistic SQL is identical, except that it does not include the ['stat'] sub-array - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_replies = topic_replies - 1, topic_last_view_time = ' . $current_time; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts - 1'; - - set_config_count('num_posts', -1, true); - - if ($auth->acl_get('f_postcount', $data['forum_id'])) - { - $sql_data[USERS_TABLE]['stat'][] = 'user_posts = user_posts - 1'; - } - - } - break; } @@ -2013,19 +1986,40 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $db->sql_query($sql); $data['post_id'] = $db->sql_nextid(); - if ($post_mode == 'post') + if ($post_mode == 'post' || $post_visibility == ITEM_APPROVED) { $sql_data[TOPICS_TABLE]['sql'] = array( - 'topic_first_post_id' => $data['post_id'], 'topic_last_post_id' => $data['post_id'], 'topic_last_post_time' => $current_time, - 'topic_last_poster_id' => (int) $user->data['user_id'], - 'topic_last_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), + 'topic_last_poster_id' => $sql_data[POSTS_TABLE]['sql']['poster_id'], + 'topic_last_poster_name' => $sql_data[POSTS_TABLE]['sql']['post_username'], 'topic_last_poster_colour' => $user->data['user_colour'], 'topic_last_post_subject' => (string) $subject, ); } + if ($post_mode == 'post') + { + $sql_data[TOPICS_TABLE]['sql']['topic_first_post_id'] = $data['post_id']; + } + + // Update total post count and forum information + if ($post_visibility == ITEM_APPROVED) + { + if ($post_mode == 'post') + { + set_config_count('num_topics', 1, true); + } + set_config_count('num_posts', 1, true); + + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id']; + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $user->data['user_id']; + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'"; + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($user->data['user_colour']) . "'"; + } + unset($sql_data[POSTS_TABLE]['sql']); } @@ -2036,6 +2030,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u SET ' . $db->sql_build_array('UPDATE', $sql_data[TOPICS_TABLE]['sql']) . ' WHERE topic_id = ' . $data['topic_id']; $db->sql_query($sql); + + unset($sql_data[TOPICS_TABLE]['sql']); } // Update the posts table @@ -2045,6 +2041,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u SET ' . $db->sql_build_array('UPDATE', $sql_data[POSTS_TABLE]['sql']) . ' WHERE post_id = ' . $data['post_id']; $db->sql_query($sql); + + unset($sql_data[POSTS_TABLE]['sql']); } // Update Poll Tables @@ -2190,114 +2188,20 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } } - // we need to update the last forum information - // only applicable if the topic is approved - if ($post_approved || $data['post_visibility'] != ITEM_APPROVED) + // Fix the post's and topic's visibility and first/last post information, when the post is edited + if (($post_mode != 'post' && $post_mode != 'reply') && $data['post_visibility'] != $post_visibility) { - // the last post makes us update the forum table. This can happen if... - // We make a new topic - // We reply to a topic - // We edit the last post in a topic and this post is the latest in the forum (maybe) - // We edit the only post in the topic - // We edit the first post in the topic and all the other posts are not approved - if (($post_mode == 'post' || $post_mode == 'reply') && $post_approved) - { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . $data['post_id']; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . $current_time; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $user->data['user_id']; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'"; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($user->data['user_colour']) . "'"; - } - else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) - { - // this does not _necessarily_ mean that we must update the info again, - // it just means that we might have to - $sql = 'SELECT forum_last_post_id, forum_last_post_subject - FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . (int) $data['forum_id']; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - // this post is the latest post in the forum, better update - if ($row['forum_last_post_id'] == $data['post_id']) - { - // If post approved and subject changed, or poster is anonymous, we need to update the forum_last* rows - if ($post_approved && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS)) - { - // the post's subject changed - if ($row['forum_last_post_subject'] !== $subject) - { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_subject = \'' . $db->sql_escape($subject) . '\''; - } + // If the post was not approved, it could also be the starter, + // so we sync the starter after approving/restoring, to ensure that the stats are correct + // Same applies for the last post + $is_starter = ($post_mode == 'edit_first_post' || $data['post_visibility'] != ITEM_APPROVED); + $is_latest = ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $data['post_visibility'] != ITEM_APPROVED); - // Update the user name if poster is anonymous... just in case an admin changed it - if ($data['poster_id'] == ANONYMOUS) - { - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'"; - } - } - else if ($data['post_visibility'] !== $post_approved) - { - // we need a fresh change of socks, everything has become invalidated - $sql = 'SELECT MAX(topic_last_post_id) as last_post_id - FROM ' . TOPICS_TABLE . ' - WHERE forum_id = ' . (int) $data['forum_id'] . ' - AND topic_visibility = ' . ITEM_APPROVED; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - // any posts left in this forum? - if (!empty($row['last_post_id'])) - { - $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour - FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u - WHERE p.poster_id = u.user_id - AND p.post_id = ' . (int) $row['last_post_id']; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - // salvation, a post is found! jam it into the forums table - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = ' . (int) $row['post_id']; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'"; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = ' . (int) $row['post_time']; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = ' . (int) $row['poster_id']; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'"; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'"; - } - else - { - // just our luck, the last topic in the forum has just been turned unapproved... - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_id = 0'; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = ''"; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_post_time = 0'; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_last_poster_id = 0'; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = ''"; - $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_colour = ''"; - } - } - } - } + phpbb_content_visibility::set_post_visibility($post_visibility, $data['post_id'], $data['topic_id'], $data['forum_id'], $user->data['user_id'], time(), '', $is_starter, $is_latest); } - - // topic sync time! - // simply, we update if it is a reply or the last post is edited - if ($post_approved) + else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) { - // reply requires the whole thing - if ($post_mode == 'reply') - { - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_id = ' . (int) $data['post_id']; - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_poster_id = ' . (int) $user->data['user_id']; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape((!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : '')) . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_colour = '" . (($user->data['user_id'] != ANONYMOUS) ? $db->sql_escape($user->data['user_colour']) : '') . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_time = ' . (int) $current_time; - } - else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) + if ($post_visibility == ITEM_APPROVED || $data['topic_visibility'] == $post_visibility) { // only the subject can be changed from edit $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($subject) . "'"; @@ -2307,57 +2211,44 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape($username) . "'"; } - } - } - else if ($data['post_visibility'] != ITEM_APPROVED && ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies']))) - { - // like having the rug pulled from under us - $sql = 'SELECT MAX(post_id) as last_post_id - FROM ' . POSTS_TABLE . ' - WHERE topic_id = ' . (int) $data['topic_id'] . ' - AND post_visibility = ' . ITEM_APPROVED; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - // any posts left in this forum? - if (!empty($row['last_post_id'])) - { - $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.user_id, u.username, u.user_colour - FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u - WHERE p.poster_id = u.user_id - AND p.post_id = ' . (int) $row['last_post_id']; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - // salvation, a post is found! jam it into the topics table - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_id = ' . (int) $row['post_id']; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_post_subject = '" . $db->sql_escape($row['post_subject']) . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_post_time = ' . (int) $row['post_time']; - $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_poster_id = ' . (int) $row['poster_id']; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_name = '" . $db->sql_escape(($row['poster_id'] == ANONYMOUS) ? $row['post_username'] : $row['username']) . "'"; - $sql_data[TOPICS_TABLE]['stat'][] = "topic_last_poster_colour = '" . $db->sql_escape($row['user_colour']) . "'"; - } - } + if ($post_visibility == ITEM_APPROVED) + { + // this does not _necessarily_ mean that we must update the info again, + // it just means that we might have to + $sql = 'SELECT forum_last_post_id, forum_last_post_subject + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . (int) $data['forum_id']; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); - // Update total post count, do not consider moderated posts/topics - if ($post_approval) - { - if ($post_mode == 'post') - { - set_config_count('num_topics', 1, true); - set_config_count('num_posts', 1, true); - } + // this post is the latest post in the forum, better update + if ($row['forum_last_post_id'] == $data['post_id'] && ($row['forum_last_post_subject'] !== $subject || $data['poster_id'] == ANONYMOUS)) + { + // the post's subject changed + if ($row['forum_last_post_subject'] !== $subject) + { + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_post_subject = '" . $db->sql_escape($subject) . "'"; + } - if ($post_mode == 'reply') - { - set_config_count('num_posts', 1, true); + // Update the user name if poster is anonymous... just in case a moderator changed it + if ($data['poster_id'] == ANONYMOUS) + { + $sql_data[FORUMS_TABLE]['stat'][] = "forum_last_poster_name = '" . $db->sql_escape($username) . "'"; + } + } + } } } // Update forum stats - $where_sql = array(POSTS_TABLE => 'post_id = ' . $data['post_id'], TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], USERS_TABLE => 'user_id = ' . $poster_id); + $where_sql = array( + POSTS_TABLE => 'post_id = ' . $data['post_id'], + TOPICS_TABLE => 'topic_id = ' . $data['topic_id'], + FORUMS_TABLE => 'forum_id = ' . $data['forum_id'], + USERS_TABLE => 'user_id = ' . $poster_id + ); foreach ($sql_data as $table => $update_ary) { @@ -2469,14 +2360,14 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } // Send Notifications - if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) + if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_visibility == ITEM_APPROVED) { user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id']); } $params = $add_anchor = ''; - if ($post_approval) + if ($post_visibility == ITEM_APPROVED) { $params .= '&t=' . $data['topic_id']; -- cgit v1.2.1 From 0822d2bb61dda3b887911d6686a8c6db05131c47 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Oct 2012 15:32:57 +0200 Subject: [feature/soft-delete] Split unapproved/soft deleted posts from topics If a topic is soft deleted through a moderator, the topic_delete_user is set. If it is passively soft deleted (f.e. while the only approved post is deleted) the topic_delete_user is not set. This way, we can distinguish between these two cases. The same also applies to unapproved posts. So we need to set the topic_delete_user when an unapproved topic is posted. Topics that were soft deleted/unapproved by a user (rather then passive) are going to be displayed in the Topics modules, while all others are in the posts modules of the MCP queue. PHPBB3-9567 --- phpBB/includes/functions_posting.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index b6223b72d4..1a0fdcee85 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1864,6 +1864,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], 'topic_visibility' => $post_visibility, + 'topic_delete_user' => ($post_visibility != ITEM_APPROVED) ? (int) $user->data['user_id'] : 0, 'topic_title' => $subject, 'topic_first_poster_name' => (!$user->data['is_registered'] && $username) ? $username : (($user->data['user_id'] != ANONYMOUS) ? $user->data['username'] : ''), 'topic_first_poster_colour' => $user->data['user_colour'], -- cgit v1.2.1 From 90154db1dbe3cd24f5af82ad5f665d607aad97ed Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Oct 2012 16:38:53 +0200 Subject: [feature/soft-delete] Fix submit_post() topic_replies* usage PHPBB3-9567 --- phpBB/includes/functions_posting.php | 47 ++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 1a0fdcee85..02b6b0e697 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1418,7 +1418,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ // Specify our post mode $post_mode = 'delete'; - if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && $data['topic_replies_real'] == 0) + if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && ($data['topic_posts'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1)) { $post_mode = 'delete_topic'; } @@ -1610,8 +1610,16 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { phpbb_content_visibility::remove_post_from_statistic($data, $sql_data); } - - $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_replies_real = topic_replies_real - 1'; + else if ($data['post_visibility'] == ITEM_UNAPPROVED) + { + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_unapproved = forum_posts_unapproved - 1'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_unapproved = topic_posts_unapproved - 1'; + } + else if ($data['post_visibility'] == ITEM_DELETED) + { + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_deleted = forum_posts_deleted - 1'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_deleted = topic_posts_deleted - 1'; + } } $sql = 'SELECT 1 AS has_attachments @@ -1702,7 +1710,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } else if ($mode == 'edit') { - $post_mode = ($data['topic_replies_real'] == 0) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); + $post_mode = ($data['topic_posts'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); } // First of all make sure the subject and topic title are having the correct length. @@ -1717,7 +1725,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Retrieve some additional information if not present if ($mode == 'edit' && (!isset($data['post_visibility']) || !isset($data['topic_visibility']) || $data['post_visibility'] === false || $data['topic_visibility'] === false)) { - $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_replies, t.topic_replies_real, t.topic_visibility + $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_posts, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_visibility FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE t.topic_id = p.topic_id AND p.post_id = ' . $data['post_id']; @@ -1900,17 +1908,28 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u if ($post_visibility == ITEM_APPROVED) { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics = forum_topics + 1'; $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; } - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_real = forum_topics_real + 1' . (($post_visibility == ITEM_APPROVED) ? ', forum_topics = forum_topics + 1' : ''); + else if ($post_visibility == ITEM_UNAPPROVED) + { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_unapproved = forum_topics_unapproved + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_unapproved = forum_posts_unapproved + 1'; + } + else if ($post_visibility == ITEM_DELETED) + { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_softdeleted = forum_topics_softdeleted + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_softdeleted = forum_posts_softdeleted + 1'; + } break; case 'reply': $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ', - topic_replies_real = topic_replies_real + 1, topic_bumped = 0, topic_bumper = 0' . - (($post_visibility == ITEM_APPROVED) ? ', topic_replies = topic_replies + 1' : '') . + (($post_visibility == ITEM_APPROVED) ? ', topic_posts = topic_posts + 1' : '') . + (($post_visibility == ITEM_UNAPPROVED) ? ', topic_posts_unapproved = topic_posts_unapproved + 1' : '') . + (($post_visibility == ITEM_DELETED) ? ', topic_posts_softdeleted = topic_posts_softdeleted + 1' : '') . ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : ''); $sql_data[USERS_TABLE]['stat'][] = "user_lastpost_time = $current_time" . (($auth->acl_get('f_postcount', $data['forum_id']) && $post_visibility == ITEM_APPROVED) ? ', user_posts = user_posts + 1' : ''); @@ -1919,6 +1938,14 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; } + else if ($post_visibility == ITEM_UNAPPROVED) + { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_unapproved = forum_posts_unapproved + 1'; + } + else if ($post_visibility == ITEM_DELETED) + { + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_softdeleted = forum_posts_softdeleted + 1'; + } break; case 'edit_topic': @@ -1979,8 +2006,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u if ($post_mode == 'reply') { $sql_data[POSTS_TABLE]['sql'] = array_merge($sql_data[POSTS_TABLE]['sql'], array( - 'topic_id' => $data['topic_id']) - ); + 'topic_id' => $data['topic_id'], + )); } $sql = 'INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_data[POSTS_TABLE]['sql']); -- cgit v1.2.1 From eb9c39971bfe7c11d62466b8fab239a8fcbc8952 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Oct 2012 17:34:37 +0200 Subject: [feature/soft-delete] Fix forum syncing in ACP and deleting posts PHPBB3-9567 --- phpBB/includes/functions_posting.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 02b6b0e697..7962690ca8 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1507,9 +1507,18 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { delete_topics('topic_id', array($topic_id), false); - - $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1'; - $sql_data[FORUMS_TABLE] .= ($data['topic_visibility'] == ITEM_APPROVED) ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : ''; + if ($data['topic_visibility'] == ITEM_APPROVED) + { + $sql_data[FORUMS_TABLE] .= 'forum_posts = forum_posts - 1, forum_topics = forum_topics - 1'; + } + else if ($data['topic_visibility'] == ITEM_UNAPPROVED) + { + $sql_data[FORUMS_TABLE] .= 'forum_posts_unapproved = forum_posts_unapproved - 1, forum_topics_unapproved = forum_topics_unapproved - 1'; + } + else if ($data['topic_visibility'] == ITEM_DELETED) + { + $sql_data[FORUMS_TABLE] .= 'forum_posts_softdeleted = forum_posts_softdeleted - 1, forum_topics_softdeleted = forum_topics_softdeleted - 1'; + } $update_sql = update_post_information('forum', $forum_id, true); if (sizeof($update_sql)) -- cgit v1.2.1 From 43e6b3a921d45150cd5c2a931e3e14758081f321 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 23 Oct 2012 15:30:52 +0200 Subject: [feature/soft-delete] Fix some more topic/post count handling Only disapproving in queue is missing. PHPBB3-9567 --- phpBB/includes/functions_posting.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 7962690ca8..473149a8ec 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1491,8 +1491,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ // counting is fun! we only have to do sizeof($forum_ids) number of queries, // even if the topic is moved back to where its shadow lives (we count how many times it is in a forum) $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET forum_topics_real = forum_topics_real - ' . $topic_count . ', - forum_topics = forum_topics - ' . $topic_count . ' + SET forum_topics = forum_topics - ' . $topic_count . ' WHERE forum_id = ' . $updated_forum; $db->sql_query($sql); update_post_information('forum', $updated_forum); -- cgit v1.2.1 From ed602857e6c5aee7b9958a3dbc9285c309b33420 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 28 Oct 2012 22:37:00 +0100 Subject: [feature/soft-delete] Correctly increase topics post counts when posting PHPBB3-9567 --- phpBB/includes/functions_posting.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 473149a8ec..807b178a4c 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1879,6 +1879,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_last_view_time' => $current_time, 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], + 'topic_posts' => ($post_visibility == ITEM_APPROVED) ? 1 : 0, + 'topic_posts_softdeleted' => ($post_visibility != ITEM_APPROVED) ? 1 : 0, 'topic_visibility' => $post_visibility, 'topic_delete_user' => ($post_visibility != ITEM_APPROVED) ? (int) $user->data['user_id'] : 0, 'topic_title' => $subject, -- cgit v1.2.1 From 63e3baf0eb37d1d8f6f0b5b46df56a673eafa6fe Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 2 Nov 2012 12:40:10 +0100 Subject: [feature/soft-delete] Correctly manage softdeleting via posting.php PHPBB3-9567 --- phpBB/includes/functions_posting.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 807b178a4c..8e8e3aac9f 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1467,7 +1467,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ } else if (!$is_soft) { - if (!delete_posts('post_id', array($post_id), false, false)) + if (!delete_posts('post_id', array($post_id), false, false, false)) { // Try to delete topic, we may had an previous error causing inconsistency if ($post_mode == 'delete_topic') @@ -1625,8 +1625,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ } else if ($data['post_visibility'] == ITEM_DELETED) { - $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_deleted = forum_posts_deleted - 1'; - $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_deleted = topic_posts_deleted - 1'; + $sql_data[FORUMS_TABLE] = (($sql_data[FORUMS_TABLE]) ? $sql_data[FORUMS_TABLE] . ', ' : '') . 'forum_posts_softdeleted = forum_posts_softdeleted - 1'; + $sql_data[TOPICS_TABLE] = (($sql_data[TOPICS_TABLE]) ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_posts_softdeleted = topic_posts_softdeleted - 1'; } } @@ -2030,7 +2030,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_last_post_id' => $data['post_id'], 'topic_last_post_time' => $current_time, 'topic_last_poster_id' => $sql_data[POSTS_TABLE]['sql']['poster_id'], - 'topic_last_poster_name' => $sql_data[POSTS_TABLE]['sql']['post_username'], + 'topic_last_poster_name' => ($user->data['user_id'] == ANONYMOUS) ? $sql_data[POSTS_TABLE]['sql']['post_username'] : $user->data['username'], 'topic_last_poster_colour' => $user->data['user_colour'], 'topic_last_post_subject' => (string) $subject, ); -- cgit v1.2.1 From 9c2a58eff4c2bd164ee3bdb2ec66729d4562963d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 9 Nov 2012 13:37:53 +0100 Subject: [feature/soft-delete] Append _approved to *_posts and *_topics column names PHPBB3-9567 --- phpBB/includes/functions_posting.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 8e8e3aac9f..62567e302a 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1418,7 +1418,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ // Specify our post mode $post_mode = 'delete'; - if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && ($data['topic_posts'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1)) + if (($data['topic_first_post_id'] === $data['topic_last_post_id']) && ($data['topic_posts_approved'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1)) { $post_mode = 'delete_topic'; } @@ -1718,7 +1718,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } else if ($mode == 'edit') { - $post_mode = ($data['topic_posts'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); + $post_mode = ($data['topic_posts_approved'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1) ? 'edit_topic' : (($data['topic_first_post_id'] == $data['post_id']) ? 'edit_first_post' : (($data['topic_last_post_id'] == $data['post_id']) ? 'edit_last_post' : 'edit')); } // First of all make sure the subject and topic title are having the correct length. @@ -1879,8 +1879,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'topic_last_view_time' => $current_time, 'forum_id' => $data['forum_id'], 'icon_id' => $data['icon_id'], - 'topic_posts' => ($post_visibility == ITEM_APPROVED) ? 1 : 0, - 'topic_posts_softdeleted' => ($post_visibility != ITEM_APPROVED) ? 1 : 0, + 'topic_posts_approved' => ($post_visibility == ITEM_APPROVED) ? 1 : 0, + 'topic_posts_softdeleted' => ($post_visibility == ITEM_DELETED) ? 1 : 0, + 'topic_posts_unapproved' => ($post_visibility == ITEM_UNAPPROVED) ? 1 : 0, 'topic_visibility' => $post_visibility, 'topic_delete_user' => ($post_visibility != ITEM_APPROVED) ? (int) $user->data['user_id'] : 0, 'topic_title' => $subject, -- cgit v1.2.1 From f77a6eaab5485329a3b13922649fb8902e6e397f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 10 Nov 2012 11:24:52 +0100 Subject: [feature/soft-delete] Fix the rest of *_approved and the delete_post unit test PHPBB3-9567 --- phpBB/includes/functions_posting.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 62567e302a..53beb6ac76 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1491,7 +1491,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ // counting is fun! we only have to do sizeof($forum_ids) number of queries, // even if the topic is moved back to where its shadow lives (we count how many times it is in a forum) $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET forum_topics = forum_topics - ' . $topic_count . ' + SET forum_topics_approved = forum_topics_approved - ' . $topic_count . ' WHERE forum_id = ' . $updated_forum; $db->sql_query($sql); update_post_information('forum', $updated_forum); @@ -1508,7 +1508,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ if ($data['topic_visibility'] == ITEM_APPROVED) { - $sql_data[FORUMS_TABLE] .= 'forum_posts = forum_posts - 1, forum_topics = forum_topics - 1'; + $sql_data[FORUMS_TABLE] .= 'forum_posts_approved = forum_posts_approved - 1, forum_topics_approved = forum_topics_approved - 1'; } else if ($data['topic_visibility'] == ITEM_UNAPPROVED) { @@ -1609,7 +1609,6 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ break; } - if (($post_mode == 'delete') || ($post_mode == 'delete_last_post') || ($post_mode == 'delete_first_post')) { if (!$is_soft) @@ -1733,7 +1732,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Retrieve some additional information if not present if ($mode == 'edit' && (!isset($data['post_visibility']) || !isset($data['topic_visibility']) || $data['post_visibility'] === false || $data['topic_visibility'] === false)) { - $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_posts, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_visibility + $sql = 'SELECT p.post_visibility, t.topic_type, t.topic_posts_approved, t.topic_posts_unapproved, t.topic_posts_softdeleted, t.topic_visibility FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE t.topic_id = p.topic_id AND p.post_id = ' . $data['post_id']; @@ -1919,8 +1918,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u if ($post_visibility == ITEM_APPROVED) { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics = forum_topics + 1'; - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_topics_approved = forum_topics_approved + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_approved = forum_posts_approved + 1'; } else if ($post_visibility == ITEM_UNAPPROVED) { @@ -1938,7 +1937,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $sql_data[TOPICS_TABLE]['stat'][] = 'topic_last_view_time = ' . $current_time . ', topic_bumped = 0, topic_bumper = 0' . - (($post_visibility == ITEM_APPROVED) ? ', topic_posts = topic_posts + 1' : '') . + (($post_visibility == ITEM_APPROVED) ? ', topic_posts_approved = topic_posts_approved + 1' : '') . (($post_visibility == ITEM_UNAPPROVED) ? ', topic_posts_unapproved = topic_posts_unapproved + 1' : '') . (($post_visibility == ITEM_DELETED) ? ', topic_posts_softdeleted = topic_posts_softdeleted + 1' : '') . ((!empty($data['attachment_data']) || (isset($data['topic_attachment']) && $data['topic_attachment'])) ? ', topic_attachment = 1' : ''); @@ -1947,7 +1946,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u if ($post_visibility == ITEM_APPROVED) { - $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts = forum_posts + 1'; + $sql_data[FORUMS_TABLE]['stat'][] = 'forum_posts_approved = forum_posts_approved + 1'; } else if ($post_visibility == ITEM_UNAPPROVED) { -- cgit v1.2.1 From 74a9ecfd24e745a0c0ad394bac915d121ea72278 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 6 Mar 2013 16:29:50 +0100 Subject: [ticket/9657] Fix wrongly added notifications when post is posted softdeleted The post/topic should not trigger "*_in_queue" notifications if it is softdeleted, as it is not in the queue then. PHPBB3-9657 --- phpBB/includes/functions_posting.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index f9dacae655..d2ff095e25 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2214,7 +2214,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u break; } } - else + else if ($post_visibility == ITEM_UNAPPROVED) { switch ($mode) { @@ -2231,6 +2231,32 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'edit_first_post': case 'edit': case 'edit_last_post': + // @todo: Check whether these notification deletions are correct + $phpbb_notifications->delete_notifications('topic', $data['topic_id']); + + $phpbb_notifications->delete_notifications(array( + 'quote', + 'bookmark', + 'post', + ), $data['post_id']); + break; + } + } + else if ($post_visibility == ITEM_DELETED) + { + switch ($mode) + { + case 'post': + case 'reply': + case 'quote': + // Nothing to do here + break; + + case 'edit_topic': + case 'edit_first_post': + case 'edit': + case 'edit_last_post': + // @todo: Check whether these notification deletions are correct $phpbb_notifications->delete_notifications('topic', $data['topic_id']); $phpbb_notifications->delete_notifications(array( -- cgit v1.2.1 From 9aed758c1397c31b979f4aca51249c73d21bd6f5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Jul 2013 14:24:07 +0200 Subject: [ticket/9657] Use the service instead of the static class PHPBB3-9657 --- phpBB/includes/functions_posting.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'phpBB/includes/functions_posting.php') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index de88f7cc98..03565c27bb 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -982,13 +982,15 @@ function load_drafts($topic_id = 0, $forum_id = 0, $id = 0, $pm_action = '', $ms function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id = 0, $show_quote_button = true) { global $user, $auth, $db, $template, $bbcode, $cache; - global $config, $phpbb_root_path, $phpEx; + global $config, $phpbb_root_path, $phpEx, $phpbb_container; + + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); // Go ahead and pull all data for this topic $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p' . " WHERE p.topic_id = $topic_id - AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.') . ' + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id, 'p.') . ' ' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . ' ' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . ' ORDER BY p.post_time '; @@ -1177,7 +1179,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id */ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $softdelete_reason = '') { - global $db, $user, $auth; + global $db, $user, $auth, $phpbb_container; global $config, $phpEx, $phpbb_root_path; // Specify our post mode @@ -1224,10 +1226,12 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $db->sql_freeresult($result); } + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + // (Soft) delete the post if ($is_soft && ($post_mode != 'delete_topic')) { - phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); + $phpbb_content_visibility->set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id)); } else if (!$is_soft) { @@ -1264,7 +1268,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ if ($is_soft) { $topic_row = array(); - phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason); + $phpbb_content_visibility->set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason); } else { @@ -1353,7 +1357,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $sql = 'SELECT MAX(post_id) as last_post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id); + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id); $result = $db->sql_query($sql); $next_post_id = (int) $db->sql_fetchfield('last_post_id'); $db->sql_freeresult($result); @@ -1364,7 +1368,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ $sql = 'SELECT post_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id) . ' + AND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id) . ' AND post_time > ' . $data['post_time'] . ' ORDER BY post_time ASC'; $result = $db->sql_query_limit($sql, 1); @@ -1379,7 +1383,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $ { if ($data['post_visibility'] == ITEM_APPROVED) { - phpbb_content_visibility::remove_post_from_statistic($data, $sql_data); + $phpbb_content_visibility->remove_post_from_statistic($data, $sql_data); } else if ($data['post_visibility'] == ITEM_UNAPPROVED) { @@ -2000,7 +2004,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $is_starter = ($post_mode == 'edit_first_post' || $data['post_visibility'] != ITEM_APPROVED); $is_latest = ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || $data['post_visibility'] != ITEM_APPROVED); - phpbb_content_visibility::set_post_visibility($post_visibility, $data['post_id'], $data['topic_id'], $data['forum_id'], $user->data['user_id'], time(), '', $is_starter, $is_latest); + $phpbb_content_visibility = $phpbb_container->get('content.visibility'); + $phpbb_content_visibility->set_post_visibility($post_visibility, $data['post_id'], $data['topic_id'], $data['forum_id'], $user->data['user_id'], time(), '', $is_starter, $is_latest); } else if ($post_mode == 'edit_last_post' || $post_mode == 'edit_topic' || ($post_mode == 'edit_first_post' && !$data['topic_replies'])) { -- cgit v1.2.1