aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/content_visibility.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-05-28 21:45:39 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-05-28 21:45:39 +0200
commite2308df14d61c91ab93a6da191b7df6f83ee5af8 (patch)
tree31da598c3aaf7012a30a43ada5131e2a83f7b4c8 /phpBB/phpbb/content_visibility.php
parentc8e7b2c5d4a8bbc33cc9cf394fa2a4f978cca63c (diff)
parentad4a373557adc93c0490471b472312483ac0b1a0 (diff)
downloadforums-e2308df14d61c91ab93a6da191b7df6f83ee5af8.tar
forums-e2308df14d61c91ab93a6da191b7df6f83ee5af8.tar.gz
forums-e2308df14d61c91ab93a6da191b7df6f83ee5af8.tar.bz2
forums-e2308df14d61c91ab93a6da191b7df6f83ee5af8.tar.xz
forums-e2308df14d61c91ab93a6da191b7df6f83ee5af8.zip
Merge pull request #2426 from Nicofuma/ticket/12174
[ticket/12174] Update topic_attachment flag when a post is soft-deleted * Nicofuma/ticket/12174: [ticket/12174] Add tests [ticket/12174] Coding style [ticket/12174] Remove $update_topic_attachments_flag [ticket/12174] Don't update the flag for a post without attachment [ticket/12174] Update the conditions [ticket/12174] Remove inline assignment [ticket/12174] Update sql query [ticket/12174] Revert the changes on $topic_update_array [ticket/12174] Corrections [ticket/12174] Update topic_attachment flag when a post is soft-deleted
Diffstat (limited to 'phpBB/phpbb/content_visibility.php')
-rw-r--r--phpBB/phpbb/content_visibility.php43
1 files changed, 35 insertions, 8 deletions
diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php
index 23927bd0de..380a479e4a 100644
--- a/phpBB/phpbb/content_visibility.php
+++ b/phpBB/phpbb/content_visibility.php
@@ -387,6 +387,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)
{
@@ -424,20 +425,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;
@@ -445,6 +440,38 @@ class content_visibility
}
}
+ if ($post_id)
+ {
+ $sql = 'SELECT 1 AS has_attachments
+ FROM ' . POSTS_TABLE . '
+ WHERE topic_id = ' . (int) $topic_id . '
+ AND post_attachment = 1
+ AND post_visibility = ' . ITEM_APPROVED . '
+ AND ' . $this->db->sql_in_set('post_id', $post_id, true);
+ $result = $this->db->sql_query_limit($sql, 1);
+
+ $has_attachment = (bool) $this->db->sql_fetchfield('has_attachments');
+ $this->db->sql_freeresult($result);
+
+ if ($has_attachment && $visibility == ITEM_APPROVED)
+ {
+ $topic_update_array[] = 'topic_attachment = 1';
+ }
+ else if (!$has_attachment && $visibility != ITEM_APPROVED)
+ {
+ $topic_update_array[] = 'topic_attachment = 0';
+ }
+ }
+
+ if (!empty($topic_update_array))
+ {
+ // 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;
}