1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

Merge branch 'develop-ascraeus' into develop

* develop-ascraeus:
  [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
This commit is contained in:
Tristan Darricau
2014-08-09 17:50:54 +02:00
3 changed files with 54 additions and 68 deletions

View File

@@ -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);
$sql_data[FORUMS_TABLE] .= 'forum_posts_approved = forum_posts_approved - 1, forum_topics_approved = forum_topics_approved - 1';
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)
{
$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';
}
// 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'];
$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))
{
$postcounts[(int) $row['num_posts']][] = (int) $row['poster_id'];
}
$this->db->sql_freeresult($result);
// Decrement users post count
foreach ($postcounts as $num_posts => $poster_ids)
{
$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);
}
}
}