1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 14:00:31 +02:00

[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
This commit is contained in:
Joas Schilling
2012-10-08 22:47:50 +02:00
parent 91398c9e48
commit 53e01bba19
2 changed files with 252 additions and 117 deletions

View File

@@ -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 (!$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'))
{
if (!$is_soft)
{
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';
}
$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';