mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/12718] Use remove_topic_from_statistic() for delete_topic
PHPBB3-12718
This commit is contained in:
parent
9b36b5283c
commit
17e360225d
2 changed files with 17 additions and 61 deletions
|
@ -1324,18 +1324,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $
|
||||||
{
|
{
|
||||||
delete_topics('topic_id', array($topic_id), false);
|
delete_topics('topic_id', array($topic_id), false);
|
||||||
|
|
||||||
if ($data['topic_visibility'] == ITEM_APPROVED)
|
$phpbb_content_visibility->remove_topic_from_statistic($data, $sql_data);
|
||||||
{
|
|
||||||
$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 || $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';
|
|
||||||
}
|
|
||||||
|
|
||||||
$update_sql = update_post_information('forum', $forum_id, true);
|
$update_sql = update_post_information('forum', $forum_id, true);
|
||||||
if (sizeof($update_sql))
|
if (sizeof($update_sql))
|
||||||
|
|
|
@ -629,58 +629,25 @@ class content_visibility
|
||||||
* @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
|
* @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 ($data['topic_visibility'] == ITEM_APPROVED)
|
||||||
if (!sizeof($topic_row))
|
|
||||||
{
|
{
|
||||||
$sql = 'SELECT topic_type, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_visibility
|
$sql_data[FORUMS_TABLE] .= 'forum_posts_approved = forum_posts_approved - 1, forum_topics_approved = forum_topics_approved - 1';
|
||||||
FROM ' . $this->topics_table . '
|
|
||||||
WHERE topic_id = ' . (int) $topic_id;
|
if ($data['post_postcount'])
|
||||||
$result = $this->db->sql_query($sql);
|
{
|
||||||
$topic_row = $this->db->sql_fetchrow($result);
|
$sql_data[$this->users_table] = ((!empty($sql_data[$this->users_table])) ? $sql_data[$this->users_table] . ', ' : '') . 'user_posts = user_posts - 1';
|
||||||
$this->db->sql_freeresult($result);
|
}
|
||||||
|
}
|
||||||
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue