diff options
author | Tristan Darricau <github@nicofuma.fr> | 2014-08-09 17:33:44 +0200 |
---|---|---|
committer | Tristan Darricau <github@nicofuma.fr> | 2014-08-09 17:33:44 +0200 |
commit | 86f94f922ce53b58d27a4f294248f5aa32fc97f8 (patch) | |
tree | 18f0cf6bdc5f1d1283358832fd0e17562655af4d /phpBB/phpbb | |
parent | 02801dee7c92d80705f64f3a1773cd39bc41a682 (diff) | |
parent | 15afaafcb67298ff7fabf3b1b4326bbc2a5975ba (diff) | |
download | forums-86f94f922ce53b58d27a4f294248f5aa32fc97f8.tar forums-86f94f922ce53b58d27a4f294248f5aa32fc97f8.tar.gz forums-86f94f922ce53b58d27a4f294248f5aa32fc97f8.tar.bz2 forums-86f94f922ce53b58d27a4f294248f5aa32fc97f8.tar.xz forums-86f94f922ce53b58d27a4f294248f5aa32fc97f8.zip |
Merge pull request #2624 from dhruvgoel92/ticket/12718
[ticket/12718] Use remove_topic_from_statistic() for delete_topic
* dhruvgoel92/ticket/12718:
[ticket/12718] Use a separate variable for sql query
[ticket/12718] Fix spacing and type casting
[ticket/12718] Fix docblocks
[ticket/12718] Add tests to check user_posts on post deletion
[ticket/12718] Update docblock
[ticket/12718] Use remove_topic_from_statistic() for delete_topic
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/content_visibility.php | 69 |
1 files changed, 17 insertions, 52 deletions
diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index da4405d676..8bd537586e 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -570,7 +570,7 @@ class content_visibility * Add post to topic and forum statistics * * @param $data array Contains information from the topics table about given topic - * @param $sql_data array Populated with the SQL changes, may be empty at call time + * @param &$sql_data array Populated with the SQL changes, may be empty at call time * @return null */ public function add_post_to_statistic($data, &$sql_data) @@ -591,7 +591,7 @@ class content_visibility * Remove post from topic and forum statistics * * @param $data array Contains information from the topics table about given topic - * @param $sql_data array Populated with the SQL changes, may be empty at call time + * @param &$sql_data array Populated with the SQL changes, may be empty at call time * @return null */ public function remove_post_from_statistic($data, &$sql_data) @@ -623,64 +623,29 @@ class content_visibility /** * Remove topic from forum statistics * - * @param $topic_id int The topic to act on - * @param $forum_id int Forum where the topic is found - * @param $topic_row array Contains information from the topic, may be empty at call time - * @param $sql_data array Populated with the SQL changes, may be empty at call time + * @param $data array Post and topic data + * @param &$sql_data array Populated with the SQL changes, may be empty at call time * @return null */ - public function remove_topic_from_statistic($topic_id, $forum_id, &$topic_row, &$sql_data) + public function remove_topic_from_statistic($data, &$sql_data) { - // Do we need to grab some topic informations? - if (!sizeof($topic_row)) + if ($data['topic_visibility'] == ITEM_APPROVED) { - $sql = 'SELECT topic_type, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_visibility - FROM ' . $this->topics_table . ' - WHERE topic_id = ' . (int) $topic_id; - $result = $this->db->sql_query($sql); - $topic_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - } - - // If this is an edited topic or the first post the topic gets completely disapproved later on... - $sql_data[$this->forums_table] = (($sql_data[$this->forums_table]) ? $sql_data[$this->forums_table] . ', ' : '') . 'forum_topics_approved = forum_topics_approved - 1'; - $sql_data[$this->forums_table] .= ', forum_posts_approved = forum_posts_approved - ' . $topic_row['topic_posts_approved']; - $sql_data[$this->forums_table] .= ', forum_posts_unapproved = forum_posts_unapproved - ' . $topic_row['topic_posts_unapproved']; - $sql_data[$this->forums_table] .= ', forum_posts_softdeleted = forum_posts_softdeleted - ' . $topic_row['topic_posts_softdeleted']; + $sql_data[FORUMS_TABLE] .= 'forum_posts_approved = forum_posts_approved - 1, forum_topics_approved = forum_topics_approved - 1'; - $this->config->increment('num_topics', -1, false); - $this->config->increment('num_posts', $topic_row['topic_posts_approved'] * (-1), false); - - // Get user post count information - $sql = 'SELECT poster_id, COUNT(post_id) AS num_posts - FROM ' . $this->posts_table . ' - WHERE topic_id = ' . (int) $topic_id . ' - AND post_postcount = 1 - AND post_visibility = ' . ITEM_APPROVED . ' - GROUP BY poster_id'; - $result = $this->db->sql_query($sql); - - $postcounts = array(); - while ($row = $this->db->sql_fetchrow($result)) + if ($data['post_postcount']) + { + $sql_data[$this->users_table] = ((!empty($sql_data[$this->users_table])) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts - 1'; + } + } + else if ($data['topic_visibility'] == ITEM_UNAPPROVED || $data['post_visibility'] == ITEM_REAPPROVE) { - $postcounts[(int) $row['num_posts']][] = (int) $row['poster_id']; + $sql_data[FORUMS_TABLE] .= 'forum_posts_unapproved = forum_posts_unapproved - 1, forum_topics_unapproved = forum_topics_unapproved - 1'; } - $this->db->sql_freeresult($result); - - // Decrement users post count - foreach ($postcounts as $num_posts => $poster_ids) + else if ($data['topic_visibility'] == ITEM_DELETED) { - $sql = 'UPDATE ' . $this->users_table . ' - SET user_posts = 0 - WHERE user_posts < ' . $num_posts . ' - AND ' . $this->db->sql_in_set('user_id', $poster_ids); - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . $this->users_table . ' - SET user_posts = user_posts - ' . $num_posts . ' - WHERE user_posts >= ' . $num_posts . ' - AND ' . $this->db->sql_in_set('user_id', $poster_ids); - $this->db->sql_query($sql); + $sql_data[FORUMS_TABLE] .= 'forum_posts_softdeleted = forum_posts_softdeleted - 1, forum_topics_softdeleted = forum_topics_softdeleted - 1'; } + } } |