mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/12174] Update topic_attachment flag when a post is soft-deleted
https://tracker.phpbb.com/browse/PHPBB3-12174 PHPBB3-12174
This commit is contained in:
parent
571d6ae852
commit
7935388306
2 changed files with 62 additions and 11 deletions
|
@ -384,6 +384,7 @@ class content_visibility
|
|||
$update_topic_postcount = false;
|
||||
}
|
||||
|
||||
$topic_update_array = array();
|
||||
// Update the topic's reply count and the forum's post count
|
||||
if ($update_topic_postcount)
|
||||
{
|
||||
|
@ -421,20 +422,14 @@ class content_visibility
|
|||
|
||||
if (sizeof($sql_ary))
|
||||
{
|
||||
$topic_sql = $forum_sql = array();
|
||||
$forum_sql = array();
|
||||
|
||||
foreach ($sql_ary as $field => $value_change)
|
||||
{
|
||||
$topic_sql[] = 'topic_' . $field . ' = topic_' . $field . $value_change;
|
||||
$topic_update_array[] = 'topic_' . $field . ' = topic_' . $field . $value_change;
|
||||
$forum_sql[] = 'forum_' . $field . ' = forum_' . $field . $value_change;
|
||||
}
|
||||
|
||||
// Update the number for replies and posts
|
||||
$sql = 'UPDATE ' . $this->topics_table . '
|
||||
SET ' . implode(', ', $topic_sql) . '
|
||||
WHERE topic_id = ' . (int) $topic_id;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$sql = 'UPDATE ' . $this->forums_table . '
|
||||
SET ' . implode(', ', $forum_sql) . '
|
||||
WHERE forum_id = ' . (int) $forum_id;
|
||||
|
@ -442,6 +437,53 @@ class content_visibility
|
|||
}
|
||||
}
|
||||
|
||||
$update_topic_attachments_flag = false;
|
||||
if ($post_id)
|
||||
{
|
||||
if (is_array($post_id))
|
||||
{
|
||||
$where_clause = $this->db->sql_in_set('post_id', array_map('intval', $post_id), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$where_clause = 'post_id <> ' . (int) $post_id;
|
||||
}
|
||||
|
||||
$sql = 'SELECT count(*) as nb_attachments
|
||||
FROM ' . POSTS_TABLE . '
|
||||
WHERE topic_id = ' . (int) $topic_id . '
|
||||
AND post_attachment = 1
|
||||
AND post_visibility = ' . ITEM_APPROVED . '
|
||||
AND ' . $where_clause;
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
if ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
if ($row['nb_attachments'] == 0)
|
||||
{
|
||||
$update_topic_attachments_flag = true;
|
||||
$topic_update_array[] = 'topic_attachment = 0';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($visibility == ITEM_APPROVED)
|
||||
{
|
||||
$update_topic_attachments_flag = true;
|
||||
$topic_update_array[] = 'topic_attachment = 1';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($update_topic_postcount || $update_topic_attachments_flag)
|
||||
{
|
||||
// Update the number for replies and posts, and update the attachments flag
|
||||
$sql = 'UPDATE ' . $this->topics_table . '
|
||||
SET ' . implode(', ', $topic_update_array) . '
|
||||
WHERE topic_id = ' . (int) $topic_id;
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
|
@ -930,7 +930,7 @@ else
|
|||
|
||||
// Container for user details, only process once
|
||||
$post_list = $user_cache = $id_cache = $attachments = $attach_list = $rowset = $update_count = $post_edit_list = $post_delete_list = array();
|
||||
$has_attachments = $display_notice = false;
|
||||
$has_unapproved_attachments = $has_approved_attachments = $display_notice = false;
|
||||
$bbcode_bitfield = '';
|
||||
$i = $i_total = 0;
|
||||
|
||||
|
@ -1041,7 +1041,11 @@ while ($row = $db->sql_fetchrow($result))
|
|||
|
||||
if ($row['post_visibility'] == ITEM_UNAPPROVED || $row['post_visibility'] == ITEM_REAPPROVE)
|
||||
{
|
||||
$has_attachments = true;
|
||||
$has_unapproved_attachments = true;
|
||||
}
|
||||
else if ($row['post_visibility'] == ITEM_APPROVED)
|
||||
{
|
||||
$has_approved_attachments = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1345,7 +1349,7 @@ if (sizeof($attach_list))
|
|||
$db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
else if ($has_attachments && !$topic_data['topic_attachment'])
|
||||
else if ($has_approved_attachments && !$topic_data['topic_attachment'])
|
||||
{
|
||||
// Topic has approved attachments but its flag is wrong
|
||||
$sql = 'UPDATE ' . TOPICS_TABLE . "
|
||||
|
@ -1355,6 +1359,11 @@ if (sizeof($attach_list))
|
|||
|
||||
$topic_data['topic_attachment'] = 1;
|
||||
}
|
||||
else if ($has_unapproved_attachments && !$topic_data['topic_attachment'])
|
||||
{
|
||||
// Topic has only unapproved attachments but we have the right to see and download them
|
||||
$topic_data['topic_attachment'] = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue