From 79353883066f1a9d5d7b0c40cbd96ce759e94382 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 8 May 2014 01:37:53 +0200 Subject: [ticket/12174] Update topic_attachment flag when a post is soft-deleted https://tracker.phpbb.com/browse/PHPBB3-12174 PHPBB3-12174 --- phpBB/phpbb/content_visibility.php | 58 ++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 8 deletions(-) (limited to 'phpBB/phpbb/content_visibility.php') diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index 881a8f2c54..e19393d3c0 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -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; } -- cgit v1.2.1 From 112e55e8ab6909f5d6fee0b566aba834c9db0c51 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 8 May 2014 19:07:18 +0200 Subject: [ticket/12174] Corrections PHPBB3-12174 --- phpBB/phpbb/content_visibility.php | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'phpBB/phpbb/content_visibility.php') diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index e19393d3c0..ff28f2a7d6 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -426,7 +426,7 @@ class content_visibility foreach ($sql_ary as $field => $value_change) { - $topic_update_array[] = 'topic_' . $field . ' = topic_' . $field . $value_change; + $topic_update_array['topic_' . $field] = 'topic_' . $field . $value_change; $forum_sql[] = 'forum_' . $field . ' = forum_' . $field . $value_change; } @@ -440,46 +440,35 @@ 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 + $sql = 'SELECT 1 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); + AND ' . $this->db->sql_in_set('post_id', $post_id, true); + $result = $this->db->sql_query_limit($sql, 1); if ($row = $this->db->sql_fetchrow($result)) { if ($row['nb_attachments'] == 0) { $update_topic_attachments_flag = true; - $topic_update_array[] = 'topic_attachment = 0'; + $topic_update_array['topic_attachment'] = 0; } - else + else if ($visibility == ITEM_APPROVED) { - if ($visibility == ITEM_APPROVED) - { - $update_topic_attachments_flag = true; - $topic_update_array[] = 'topic_attachment = 1'; - } + $update_topic_attachments_flag = true; + $topic_update_array['topic_attachment'] = 1; } } + $this->db->sql_freeresult($result); } 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) . ' + SET ' . $this->db->sql_build_array('UPDATE', $topic_update_array) . ' WHERE topic_id = ' . (int) $topic_id; $this->db->sql_query($sql); } -- cgit v1.2.1 From 51c93aeb025a11930611a792b364502824314e03 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 8 May 2014 19:48:00 +0200 Subject: [ticket/12174] Revert the changes on $topic_update_array PHPBB3-12174 --- phpBB/phpbb/content_visibility.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/content_visibility.php') diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index ff28f2a7d6..420a43ec98 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -426,7 +426,7 @@ class content_visibility foreach ($sql_ary as $field => $value_change) { - $topic_update_array['topic_' . $field] = 'topic_' . $field . $value_change; + $topic_update_array[] = 'topic_' . $field . ' = topic_' . $field . $value_change; $forum_sql[] = 'forum_' . $field . ' = forum_' . $field . $value_change; } @@ -453,12 +453,12 @@ class content_visibility if ($row['nb_attachments'] == 0) { $update_topic_attachments_flag = true; - $topic_update_array['topic_attachment'] = 0; + $topic_update_array[] = 'topic_attachment = 0'; } else if ($visibility == ITEM_APPROVED) { $update_topic_attachments_flag = true; - $topic_update_array['topic_attachment'] = 1; + $topic_update_array[] = 'topic_attachment = 1'; } } $this->db->sql_freeresult($result); @@ -468,7 +468,7 @@ class content_visibility { // Update the number for replies and posts, and update the attachments flag $sql = 'UPDATE ' . $this->topics_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $topic_update_array) . ' + SET ' . implode(', ', $topic_update_array) . ' WHERE topic_id = ' . (int) $topic_id; $this->db->sql_query($sql); } -- cgit v1.2.1 From f755f696069c48e40cba8163b04ea8537354283f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 9 May 2014 00:18:38 +0200 Subject: [ticket/12174] Update sql query PHPBB3-12174 --- phpBB/phpbb/content_visibility.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'phpBB/phpbb/content_visibility.php') diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index 420a43ec98..7cb7bd6922 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -440,7 +440,7 @@ class content_visibility $update_topic_attachments_flag = false; if ($post_id) { - $sql = 'SELECT 1 as nb_attachments + $sql = 'SELECT 1 as has_attachments FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . (int) $topic_id . ' AND post_attachment = 1 @@ -450,17 +450,18 @@ class content_visibility 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) + if ($visibility == ITEM_APPROVED) { $update_topic_attachments_flag = true; $topic_update_array[] = 'topic_attachment = 1'; } } + else + { + $update_topic_attachments_flag = true; + $topic_update_array[] = 'topic_attachment = 0'; + } + $this->db->sql_freeresult($result); } @@ -468,8 +469,8 @@ class content_visibility { // 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; + SET ' . implode(', ', $topic_update_array) . ' + WHERE topic_id = ' . (int) $topic_id; $this->db->sql_query($sql); } -- cgit v1.2.1 From a80ad5d00f66d5195cdfe1c953079b54d27063dc Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 9 May 2014 00:31:53 +0200 Subject: [ticket/12174] Remove inline assignment PHPBB3-12174 --- phpBB/phpbb/content_visibility.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/content_visibility.php') diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index 7cb7bd6922..f532d7e61e 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -448,7 +448,8 @@ class content_visibility AND ' . $this->db->sql_in_set('post_id', $post_id, true); $result = $this->db->sql_query_limit($sql, 1); - if ($row = $this->db->sql_fetchrow($result)) + $row = $this->db->sql_fetchrow($result); + if ($row != false) { if ($visibility == ITEM_APPROVED) { -- cgit v1.2.1 From 712491697e79e5af80df6ad8a563ea3a1601a1a4 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 9 May 2014 00:46:56 +0200 Subject: [ticket/12174] Update the conditions PHPBB3-12174 --- phpBB/phpbb/content_visibility.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'phpBB/phpbb/content_visibility.php') diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index f532d7e61e..c587c2b07b 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -448,22 +448,19 @@ class content_visibility AND ' . $this->db->sql_in_set('post_id', $post_id, true); $result = $this->db->sql_query_limit($sql, 1); - $row = $this->db->sql_fetchrow($result); - if ($row != false) + $has_attachment = (bool) $this->db->sql_fetchfield('has_attachments'); + $this->db->sql_freeresult($result); + + if ($has_attachment && $visibility == ITEM_APPROVED) { - if ($visibility == ITEM_APPROVED) - { - $update_topic_attachments_flag = true; - $topic_update_array[] = 'topic_attachment = 1'; - } + $update_topic_attachments_flag = true; + $topic_update_array[] = 'topic_attachment = 1'; } - else + else if (!$has_attachment) { $update_topic_attachments_flag = true; $topic_update_array[] = 'topic_attachment = 0'; } - - $this->db->sql_freeresult($result); } if ($update_topic_postcount || $update_topic_attachments_flag) -- cgit v1.2.1 From 93f901d078a706368925e50b60d9b086d7ce01e3 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 9 May 2014 00:50:34 +0200 Subject: [ticket/12174] Don't update the flag for a post without attachment PHPBB3-12174 --- phpBB/phpbb/content_visibility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/content_visibility.php') diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index c587c2b07b..42bf8cf44b 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -456,7 +456,7 @@ class content_visibility $update_topic_attachments_flag = true; $topic_update_array[] = 'topic_attachment = 1'; } - else if (!$has_attachment) + else if (!$has_attachment && $visibility != ITEM_APPROVED) { $update_topic_attachments_flag = true; $topic_update_array[] = 'topic_attachment = 0'; -- cgit v1.2.1 From 27cb84d3d483ecac19ba51be17d97306ae436ba8 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 9 May 2014 09:48:09 +0200 Subject: [ticket/12174] Remove $update_topic_attachments_flag PHPBB3-12174 --- phpBB/phpbb/content_visibility.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'phpBB/phpbb/content_visibility.php') diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index 42bf8cf44b..bced0a3247 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -437,7 +437,6 @@ class content_visibility } } - $update_topic_attachments_flag = false; if ($post_id) { $sql = 'SELECT 1 as has_attachments @@ -453,17 +452,15 @@ class content_visibility if ($has_attachment && $visibility == ITEM_APPROVED) { - $update_topic_attachments_flag = true; $topic_update_array[] = 'topic_attachment = 1'; } else if (!$has_attachment && $visibility != ITEM_APPROVED) { - $update_topic_attachments_flag = true; $topic_update_array[] = 'topic_attachment = 0'; } } - if ($update_topic_postcount || $update_topic_attachments_flag) + if (!empty($topic_update_array)) { // Update the number for replies and posts, and update the attachments flag $sql = 'UPDATE ' . $this->topics_table . ' -- cgit v1.2.1 From ca5987ceb863d557bd3509e164f9fe982aecb00d Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 10 May 2014 23:50:42 +0200 Subject: [ticket/12174] Coding style PHPBB3-12174 --- phpBB/phpbb/content_visibility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/content_visibility.php') diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index bced0a3247..c186e7f765 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -439,7 +439,7 @@ class content_visibility if ($post_id) { - $sql = 'SELECT 1 as has_attachments + $sql = 'SELECT 1 AS has_attachments FROM ' . POSTS_TABLE . ' WHERE topic_id = ' . (int) $topic_id . ' AND post_attachment = 1 -- cgit v1.2.1