diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2012-10-23 23:37:25 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2012-10-23 23:37:25 +0200 |
commit | b3d5f2b4e42404610f5db8dda25859db942fd60e (patch) | |
tree | bccaaffac02c2a94ffb5ca705a7e276f37addf7b /phpBB | |
parent | 3236229188d9b36105633223f4b2df6c6b3eb0ad (diff) | |
download | forums-b3d5f2b4e42404610f5db8dda25859db942fd60e.tar forums-b3d5f2b4e42404610f5db8dda25859db942fd60e.tar.gz forums-b3d5f2b4e42404610f5db8dda25859db942fd60e.tar.bz2 forums-b3d5f2b4e42404610f5db8dda25859db942fd60e.tar.xz forums-b3d5f2b4e42404610f5db8dda25859db942fd60e.zip |
[feature/soft-delete] Fix unit tests for delete_posts()
PHPBB3-9567
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/includes/content_visibility.php | 71 | ||||
-rw-r--r-- | phpBB/includes/functions_admin.php | 2 |
2 files changed, 56 insertions, 17 deletions
diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 20e743a4c4..da7e6b9c4f 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -348,34 +348,75 @@ class phpbb_content_visibility // Update the topic's reply count and the forum's post count if ($update_topic_postcount) { - $num_posts = 0; + $cur_posts = $cur_unapproved_posts = $cur_softdeleted_posts = 0; foreach ($postcount_visibility as $post_visibility => $visibility_posts) { - // If we soft delete, we need to substract approved posts from the counters ... - if ($post_visibility == ITEM_APPROVED && $visibility == ITEM_DELETED) + // We need to substract the posts from the counters ... + if ($post_visibility == ITEM_APPROVED) { - $num_posts += $visibility_posts; + $cur_posts += $visibility_posts; } - // ... and when we approve/restore, all others. - else if ($post_visibility != ITEM_APPROVED && $visibility == ITEM_APPROVED) + else if ($post_visibility == ITEM_UNAPPROVED) { - $num_posts += $visibility_posts; + $cur_unapproved_posts += $visibility_posts; + } + else if ($post_visibility == ITEM_DELETED) + { + $cur_softdeleted_posts += $visibility_posts; + } + } + + $sql_ary = array(); + if ($visibility == ITEM_DELETED) + { + if ($cur_posts) + { + $sql_ary['posts'] = ' - ' . $cur_posts; + } + if ($cur_unapproved_posts) + { + $sql_ary['posts_unapproved'] = ' - ' . $cur_unapproved_posts; + } + if ($cur_posts + $cur_unapproved_posts) + { + $sql_ary['posts_softdeleted'] = ' + ' . ($cur_posts + $cur_unapproved_posts); + } + } + else + { + if ($cur_unapproved_posts) + { + $sql_ary['posts_unapproved'] = ' - ' . $cur_unapproved_posts; + } + if ($cur_softdeleted_posts) + { + $sql_ary['posts_softdeleted'] = ' - ' . $cur_softdeleted_posts; + } + if ($cur_posts + $cur_unapproved_posts) + { + $sql_ary['posts'] = ' + ' . ($cur_softdeleted_posts + $cur_unapproved_posts); } } - if ($num_posts) + if (sizeof($sql_ary)) { - $sql_num_posts = (($visibility == ITEM_DELETED) ? ' - ' : ' + ') . $num_posts; + $topic_sql = $forum_sql = array(); + + foreach ($sql_ary as $field => $value_change) + { + $topic_sql[] = 'topic_' . $field . ' = topic_' . $field . $value_change; + $forum_sql[] = 'forum_' . $field . ' = forum_' . $field . $value_change; + } // Update the number for replies and posts - $sql = 'UPDATE ' . TOPICS_TABLE . " - SET topic_replies = topic_replies $sql_num_posts - WHERE topic_id = $topic_id"; + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET ' . implode(', ', $topic_sql) . ' + WHERE topic_id = ' . $topic_id; $db->sql_query($sql); - $sql = 'UPDATE ' . FORUMS_TABLE . " - SET forum_posts = forum_posts $sql_num_posts - WHERE forum_id = $forum_id"; + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET ' . implode(', ', $forum_sql) . ' + WHERE forum_id = ' . $forum_id; $db->sql_query($sql); } } diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index a38fa2a70f..e2a133270b 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -1729,7 +1729,6 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $sql = 'SELECT SUM(t.topic_posts) AS forum_posts, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_visibility = ' . ITEM_APPROVED . ' AND t.topic_status <> ' . ITEM_MOVED; } else @@ -1737,7 +1736,6 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false, $sql = 'SELECT t.forum_id, SUM(t.topic_posts) AS forum_posts, SUM(t.topic_posts_unapproved) AS forum_posts_unapproved, SUM(t.topic_posts_softdeleted) AS forum_posts_softdeleted FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('t.forum_id', $forum_ids) . ' - AND t.topic_visibility = ' . ITEM_APPROVED . ' AND t.topic_status <> ' . ITEM_MOVED . ' GROUP BY t.forum_id'; } |