From fd6ee50e06cb48c9e3a476bf23285875484ff5f7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 2 Nov 2012 16:05:53 -0400 Subject: [PATCH 01/34] [ticket/11162] Extract existing behavior into a function and add a test. PHPBB3-11162 --- phpBB/includes/functions.php | 24 ++++++- tests/functions/fixtures/duplicates.xml | 56 +++++++++++++++ .../update_rows_avoiding_duplicates_test.php | 71 +++++++++++++++++++ 3 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 tests/functions/fixtures/duplicates.xml create mode 100644 tests/functions/update_rows_avoiding_duplicates_test.php diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 65d8be32ad..8608c6ca4f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1297,6 +1297,28 @@ function tz_select($default = '', $truncate = false) return $tz_select; } +/** +* Updates rows in given table from a set of values to a new value. +* If this results in rows violating uniqueness constraints, the duplicate +* rows are eliminated. +* +* @param dbal $db Database object +* @param string $table Table on which to perform the update +* @param string $column Column whose values to change +* @param array $from_values An array of values that should be changed +* @param int $to_value The new value +* @return null +*/ +function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_values, $to_value) +{ + $db->sql_return_on_error(true); + $condition = $db->sql_in_set($column, $from_values); + $db->sql_query('UPDATE ' . $table . ' SET ' . $column . ' = ' . (int) $to_value. ' WHERE ' . $condition); + $db->sql_return_on_error(false); + + $db->sql_query('DELETE FROM ' . $table . ' WHERE ' . $condition); +} + // Functions handling topic/post tracking/marking /** @@ -3355,7 +3377,7 @@ function parse_cfg_file($filename, $lines = false) $parsed_items[$key] = $value; } - + if (isset($parsed_items['inherit_from']) && isset($parsed_items['name']) && $parsed_items['inherit_from'] == $parsed_items['name']) { unset($parsed_items['inherit_from']); diff --git a/tests/functions/fixtures/duplicates.xml b/tests/functions/fixtures/duplicates.xml new file mode 100644 index 0000000000..bc08016a8f --- /dev/null +++ b/tests/functions/fixtures/duplicates.xml @@ -0,0 +1,56 @@ + + + + user_id + topic_id + notify_status + + + + 1 + 1 + 1 + + + + + 2 + 2 + 1 + + + 3 + 3 + 1 + + + + + 1 + 4 + 1 + + + 1 + 5 + 1 + + + + + 1 + 6 + 1 + + + 1 + 7 + 1 + + + 2 + 6 + 1 + +
+
diff --git a/tests/functions/update_rows_avoiding_duplicates_test.php b/tests/functions/update_rows_avoiding_duplicates_test.php new file mode 100644 index 0000000000..0e949717d2 --- /dev/null +++ b/tests/functions/update_rows_avoiding_duplicates_test.php @@ -0,0 +1,71 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/duplicates.xml'); + } + + public static function fixture_data() + { + return array( + // description + // from array + // to value + // expected count with to value post update + array( + 'trivial', + array(1), + 10, + 1, + ), + array( + 'no conflict', + array(2), + 3, + 2, + ), + array( + 'conflict', + array(4), + 5, + 1, + ), + array( + 'conflict and no conflict', + array(6), + 7, + 2, + ), + ); + } + + /** + * @dataProvider fixture_data + */ + public function test_trivial_update($description, $from, $to, $expected_result_count) + { + $db = $this->new_dbal(); + + phpbb_update_rows_avoiding_duplicates($db, TOPICS_WATCH_TABLE, 'topic_id', $from, $to); + + $sql = 'SELECT count(*) AS count + FROM ' . TOPICS_WATCH_TABLE . ' + WHERE topic_id = ' . $db->sql_escape($to); + $result = $db->sql_query($sql); + $result_count = $db->sql_fetchfield('count'); + $db->sql_freeresult($result); + + $this->assertEquals($expected_result_count, $result_count); + } +} From b0812c43fa05bec8c59e5ff3c7889f0f98089775 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 11 Nov 2012 17:40:58 +0100 Subject: [PATCH 02/34] [ticket/11162] Use integer casting instead of SQL escape. PHPBB3-11162 --- tests/functions/update_rows_avoiding_duplicates_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functions/update_rows_avoiding_duplicates_test.php b/tests/functions/update_rows_avoiding_duplicates_test.php index 0e949717d2..e4e156209d 100644 --- a/tests/functions/update_rows_avoiding_duplicates_test.php +++ b/tests/functions/update_rows_avoiding_duplicates_test.php @@ -61,7 +61,7 @@ class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_cas $sql = 'SELECT count(*) AS count FROM ' . TOPICS_WATCH_TABLE . ' - WHERE topic_id = ' . $db->sql_escape($to); + WHERE topic_id = ' . (int) $to; $result = $db->sql_query($sql); $result_count = $db->sql_fetchfield('count'); $db->sql_freeresult($result); From 7d0cc15b926dda1a53b8151e063e2ffda7441240 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 11 Nov 2012 17:48:59 +0100 Subject: [PATCH 03/34] [ticket/11162] Rename count variable name to remaining_rows. PHPBB3-11162 --- tests/functions/update_rows_avoiding_duplicates_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functions/update_rows_avoiding_duplicates_test.php b/tests/functions/update_rows_avoiding_duplicates_test.php index e4e156209d..0c9ae068a4 100644 --- a/tests/functions/update_rows_avoiding_duplicates_test.php +++ b/tests/functions/update_rows_avoiding_duplicates_test.php @@ -59,11 +59,11 @@ class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_cas phpbb_update_rows_avoiding_duplicates($db, TOPICS_WATCH_TABLE, 'topic_id', $from, $to); - $sql = 'SELECT count(*) AS count + $sql = 'SELECT count(*) AS remaining_rows FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $to; $result = $db->sql_query($sql); - $result_count = $db->sql_fetchfield('count'); + $result_count = $db->sql_fetchfield('remaining_rows'); $db->sql_freeresult($result); $this->assertEquals($expected_result_count, $result_count); From ac9c4d7d59ea458834cb64b9c9020c3de8fe90a2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 11 Nov 2012 17:49:21 +0100 Subject: [PATCH 04/34] [ticket/11162] Make count function upper case. PHPBB3-11162 --- tests/functions/update_rows_avoiding_duplicates_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functions/update_rows_avoiding_duplicates_test.php b/tests/functions/update_rows_avoiding_duplicates_test.php index 0c9ae068a4..0d68e22d4a 100644 --- a/tests/functions/update_rows_avoiding_duplicates_test.php +++ b/tests/functions/update_rows_avoiding_duplicates_test.php @@ -59,7 +59,7 @@ class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_cas phpbb_update_rows_avoiding_duplicates($db, TOPICS_WATCH_TABLE, 'topic_id', $from, $to); - $sql = 'SELECT count(*) AS remaining_rows + $sql = 'SELECT COUNT(*) AS remaining_rows FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $to; $result = $db->sql_query($sql); From d0338531cb2a3a386a3894a1b1b081025f53ea05 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 20:12:31 -0500 Subject: [PATCH 05/34] [ticket/11162] An implementation that actually works. PHPBB3-11162 --- phpBB/includes/functions.php | 73 +++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 8608c6ca4f..13690e79bb 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1311,12 +1311,75 @@ function tz_select($default = '', $truncate = false) */ function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_values, $to_value) { - $db->sql_return_on_error(true); - $condition = $db->sql_in_set($column, $from_values); - $db->sql_query('UPDATE ' . $table . ' SET ' . $column . ' = ' . (int) $to_value. ' WHERE ' . $condition); - $db->sql_return_on_error(false); + $sql = "SELECT $column, user_id + FROM $table + WHERE " . $db->sql_in_set($column, $from_values); + $result = $db->sql_query($sql); - $db->sql_query('DELETE FROM ' . $table . ' WHERE ' . $condition); + $old_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $old_user_ids[$row[$column]][] = $row['user_id']; + } + $db->sql_freeresult($result); + + $sql = "SELECT $column, user_id + FROM $table + WHERE $column = '" . (int) $to_value . "'"; + $result = $db->sql_query($sql); + + $new_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $new_user_ids[$row[$column]][] = $row['user_id']; + } + $db->sql_freeresult($result); + + $queries = array(); + $any_found = false; + foreach ($from_values as $from_value) + { + if (!isset($old_user_ids[$from_value])) + { + continue; + } + $any_found = true; + if (empty($new_user_ids)) + { + $sql = "UPDATE $table + SET $column = " . (int) $to_value. " + WHERE $column = '" . $db->sql_escape($from_value) . "'"; + $queries[] = $sql; + } + else + { + $different_user_ids = array_diff($old_user_ids[$from_value], $new_user_ids[$to_value]); + if (!empty($different_user_ids)) + { + $sql = "UPDATE $table + SET $column = " . (int) $to_value. " + WHERE $column = '" . $db->sql_escape($from_value) . "' + AND " . $db->sql_in_set('user_id', $different_user_ids); + $queries[] = $sql; + } + } + } + + if ($any_found) + { + //$db->sql_transaction('begin'); + + foreach ($queries as $sql) + { + $db->sql_query($sql); + } + + $sql = "DELETE FROM $table + WHERE " . $db->sql_in_set($column, $from_values); + $db->sql_query($sql); + + //$db->sql_transaction('commit'); + } } // Functions handling topic/post tracking/marking From 2e947334e563f122c597d7072eddd962453a84ef Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 20:17:01 -0500 Subject: [PATCH 06/34] [ticket/11162] Uncomment transactions. PHPBB3-11162 --- phpBB/includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 13690e79bb..a24dcfdf5b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1367,7 +1367,7 @@ function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_value if ($any_found) { - //$db->sql_transaction('begin'); + $db->sql_transaction('begin'); foreach ($queries as $sql) { @@ -1378,7 +1378,7 @@ function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_value WHERE " . $db->sql_in_set($column, $from_values); $db->sql_query($sql); - //$db->sql_transaction('commit'); + $db->sql_transaction('commit'); } } From c2c105df9ff1d8fd48afa1d3abdf23a39584d7ed Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 20:21:29 -0500 Subject: [PATCH 07/34] [ticket/11162] Clarify that only the two tables actually work. PHPBB3-11162 --- phpBB/includes/functions.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index a24dcfdf5b..09487ce10d 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1302,6 +1302,8 @@ function tz_select($default = '', $truncate = false) * If this results in rows violating uniqueness constraints, the duplicate * rows are eliminated. * +* The only supported tables are bookmarks and topics_watch. +* * @param dbal $db Database object * @param string $table Table on which to perform the update * @param string $column Column whose values to change From 69225bd0a6005e81b7cb58631eb5de7c3d175697 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 20:21:51 -0500 Subject: [PATCH 08/34] [ticket/11162] Use phpbb_update_rows_avoiding_duplicates in mcp. PHPBB3-11162 --- phpBB/includes/mcp/mcp_forum.php | 7 +------ phpBB/includes/mcp/mcp_topic.php | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index b70601b479..913c55a9d1 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -415,12 +415,7 @@ function merge_topics($forum_id, $topic_ids, $to_topic_id) $success_msg = 'POSTS_MERGED_SUCCESS'; // If the topic no longer exist, we will update the topic watch table. - // To not let it error out on users watching both topics, we just return on an error... - $db->sql_return_on_error(true); - $db->sql_query('UPDATE ' . TOPICS_WATCH_TABLE . ' SET topic_id = ' . (int) $to_topic_id . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids)); - $db->sql_return_on_error(false); - - $db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids)); + phpbb_update_rows_avoiding_duplicates($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); // Link to the new topic $return_link .= (($return_link) ? '

' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '', ''); diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index 7d4edaf362..f40a4bc044 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -620,12 +620,7 @@ function merge_posts($topic_id, $to_topic_id) else { // If the topic no longer exist, we will update the topic watch table. - // To not let it error out on users watching both topics, we just return on an error... - $db->sql_return_on_error(true); - $db->sql_query('UPDATE ' . TOPICS_WATCH_TABLE . ' SET topic_id = ' . (int) $to_topic_id . ' WHERE topic_id = ' . (int) $topic_id); - $db->sql_return_on_error(false); - - $db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $topic_id); + phpbb_update_rows_avoiding_duplicates($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); } // Link to the new topic From 05053dacd350c6bacd529df803bdc9876104a278 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 20:24:25 -0500 Subject: [PATCH 09/34] [ticket/11162] Fix inaccurately copy pasted comment. PHPBB3-11162 --- phpBB/includes/mcp/mcp_forum.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 913c55a9d1..e392bef157 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -414,7 +414,7 @@ function merge_topics($forum_id, $topic_ids, $to_topic_id) // Message and return links $success_msg = 'POSTS_MERGED_SUCCESS'; - // If the topic no longer exist, we will update the topic watch table. + // Update the topic watch table. phpbb_update_rows_avoiding_duplicates($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); // Link to the new topic From 2fc43e6ed71e4b9abdb76aa179b4e64efaa47ffa Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 23:11:14 -0500 Subject: [PATCH 10/34] [ticket/11162] No whitespace changes in olympus. PHPBB3-11162 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 09487ce10d..e3feb59d41 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3442,7 +3442,7 @@ function parse_cfg_file($filename, $lines = false) $parsed_items[$key] = $value; } - + if (isset($parsed_items['inherit_from']) && isset($parsed_items['name']) && $parsed_items['inherit_from'] == $parsed_items['name']) { unset($parsed_items['inherit_from']); From 0f96b1aad378b1fc40620ea57df5ee89224fd5eb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 23:35:34 -0500 Subject: [PATCH 11/34] [ticket/11162] Move to a separate file to avoid blowing out functions.php. PHPBB3-11162 --- phpBB/includes/functions.php | 87 --------------- phpBB/includes/functions_tricky_update.php | 103 ++++++++++++++++++ .../fixtures/duplicates.xml | 0 .../update_rows_avoiding_duplicates_test.php | 2 +- 4 files changed, 104 insertions(+), 88 deletions(-) create mode 100644 phpBB/includes/functions_tricky_update.php rename tests/{functions => functions_tricky_update}/fixtures/duplicates.xml (100%) rename tests/{functions => functions_tricky_update}/update_rows_avoiding_duplicates_test.php (98%) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index e3feb59d41..65d8be32ad 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1297,93 +1297,6 @@ function tz_select($default = '', $truncate = false) return $tz_select; } -/** -* Updates rows in given table from a set of values to a new value. -* If this results in rows violating uniqueness constraints, the duplicate -* rows are eliminated. -* -* The only supported tables are bookmarks and topics_watch. -* -* @param dbal $db Database object -* @param string $table Table on which to perform the update -* @param string $column Column whose values to change -* @param array $from_values An array of values that should be changed -* @param int $to_value The new value -* @return null -*/ -function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_values, $to_value) -{ - $sql = "SELECT $column, user_id - FROM $table - WHERE " . $db->sql_in_set($column, $from_values); - $result = $db->sql_query($sql); - - $old_user_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $old_user_ids[$row[$column]][] = $row['user_id']; - } - $db->sql_freeresult($result); - - $sql = "SELECT $column, user_id - FROM $table - WHERE $column = '" . (int) $to_value . "'"; - $result = $db->sql_query($sql); - - $new_user_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $new_user_ids[$row[$column]][] = $row['user_id']; - } - $db->sql_freeresult($result); - - $queries = array(); - $any_found = false; - foreach ($from_values as $from_value) - { - if (!isset($old_user_ids[$from_value])) - { - continue; - } - $any_found = true; - if (empty($new_user_ids)) - { - $sql = "UPDATE $table - SET $column = " . (int) $to_value. " - WHERE $column = '" . $db->sql_escape($from_value) . "'"; - $queries[] = $sql; - } - else - { - $different_user_ids = array_diff($old_user_ids[$from_value], $new_user_ids[$to_value]); - if (!empty($different_user_ids)) - { - $sql = "UPDATE $table - SET $column = " . (int) $to_value. " - WHERE $column = '" . $db->sql_escape($from_value) . "' - AND " . $db->sql_in_set('user_id', $different_user_ids); - $queries[] = $sql; - } - } - } - - if ($any_found) - { - $db->sql_transaction('begin'); - - foreach ($queries as $sql) - { - $db->sql_query($sql); - } - - $sql = "DELETE FROM $table - WHERE " . $db->sql_in_set($column, $from_values); - $db->sql_query($sql); - - $db->sql_transaction('commit'); - } -} - // Functions handling topic/post tracking/marking /** diff --git a/phpBB/includes/functions_tricky_update.php b/phpBB/includes/functions_tricky_update.php new file mode 100644 index 0000000000..a5b9fdacd0 --- /dev/null +++ b/phpBB/includes/functions_tricky_update.php @@ -0,0 +1,103 @@ +sql_in_set($column, $from_values); + $result = $db->sql_query($sql); + + $old_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $old_user_ids[$row[$column]][] = $row['user_id']; + } + $db->sql_freeresult($result); + + $sql = "SELECT $column, user_id + FROM $table + WHERE $column = '" . (int) $to_value . "'"; + $result = $db->sql_query($sql); + + $new_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $new_user_ids[$row[$column]][] = $row['user_id']; + } + $db->sql_freeresult($result); + + $queries = array(); + $any_found = false; + foreach ($from_values as $from_value) + { + if (!isset($old_user_ids[$from_value])) + { + continue; + } + $any_found = true; + if (empty($new_user_ids)) + { + $sql = "UPDATE $table + SET $column = " . (int) $to_value. " + WHERE $column = '" . $db->sql_escape($from_value) . "'"; + $queries[] = $sql; + } + else + { + $different_user_ids = array_diff($old_user_ids[$from_value], $new_user_ids[$to_value]); + if (!empty($different_user_ids)) + { + $sql = "UPDATE $table + SET $column = " . (int) $to_value. " + WHERE $column = '" . $db->sql_escape($from_value) . "' + AND " . $db->sql_in_set('user_id', $different_user_ids); + $queries[] = $sql; + } + } + } + + if ($any_found) + { + $db->sql_transaction('begin'); + + foreach ($queries as $sql) + { + $db->sql_query($sql); + } + + $sql = "DELETE FROM $table + WHERE " . $db->sql_in_set($column, $from_values); + $db->sql_query($sql); + + $db->sql_transaction('commit'); + } +} diff --git a/tests/functions/fixtures/duplicates.xml b/tests/functions_tricky_update/fixtures/duplicates.xml similarity index 100% rename from tests/functions/fixtures/duplicates.xml rename to tests/functions_tricky_update/fixtures/duplicates.xml diff --git a/tests/functions/update_rows_avoiding_duplicates_test.php b/tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php similarity index 98% rename from tests/functions/update_rows_avoiding_duplicates_test.php rename to tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php index 0d68e22d4a..6940122393 100644 --- a/tests/functions/update_rows_avoiding_duplicates_test.php +++ b/tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_tricky_update.php'; class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_case { From abca64b1dfbe11f73675a3e5457fb9f0038f1cb6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 23:37:14 -0500 Subject: [PATCH 12/34] [ticket/11162] Add includes. PHPBB3-11162 --- phpBB/includes/mcp/mcp_forum.php | 4 ++++ phpBB/includes/mcp/mcp_topic.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index e392bef157..3603224735 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -415,6 +415,10 @@ function merge_topics($forum_id, $topic_ids, $to_topic_id) $success_msg = 'POSTS_MERGED_SUCCESS'; // Update the topic watch table. + if (!function_exists('phpbb_update_rows_avoiding_duplicates')) + { + include($phpbb_root_path . 'includes/functions_tricky_update.' . $phpEx); + } phpbb_update_rows_avoiding_duplicates($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); // Link to the new topic diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index f40a4bc044..1fb3cb9d73 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -620,6 +620,10 @@ function merge_posts($topic_id, $to_topic_id) else { // If the topic no longer exist, we will update the topic watch table. + if (!function_exists('phpbb_update_rows_avoiding_duplicates')) + { + include($phpbb_root_path . 'includes/functions_tricky_update.' . $phpEx); + } phpbb_update_rows_avoiding_duplicates($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); } From 58951ef1057bd5f0d1098f9536eb8a84c532833c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 23:37:57 -0500 Subject: [PATCH 13/34] [ticket/11162] The test is not at all trivial. PHPBB3-11162 --- .../update_rows_avoiding_duplicates_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php b/tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php index 6940122393..4849605e9c 100644 --- a/tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php +++ b/tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php @@ -53,7 +53,7 @@ class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_cas /** * @dataProvider fixture_data */ - public function test_trivial_update($description, $from, $to, $expected_result_count) + public function test_update($description, $from, $to, $expected_result_count) { $db = $this->new_dbal(); From efe122b03200155479920890defc2a3dc689bdd7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 23:40:30 -0500 Subject: [PATCH 14/34] [ticket/11162] This test really only works for bookmarks. PHPBB3-11162 --- .../fixtures/bookmarks_duplicates.xml | 47 +++++++++++++++++++ ...icates.xml => topics_watch_duplicates.xml} | 0 .../update_rows_avoiding_duplicates_test.php | 6 +-- 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 tests/functions_tricky_update/fixtures/bookmarks_duplicates.xml rename tests/functions_tricky_update/fixtures/{duplicates.xml => topics_watch_duplicates.xml} (100%) diff --git a/tests/functions_tricky_update/fixtures/bookmarks_duplicates.xml b/tests/functions_tricky_update/fixtures/bookmarks_duplicates.xml new file mode 100644 index 0000000000..d49f76b073 --- /dev/null +++ b/tests/functions_tricky_update/fixtures/bookmarks_duplicates.xml @@ -0,0 +1,47 @@ + + + + user_id + topic_id + + + + 1 + 1 + + + + + 2 + 2 + + + 3 + 3 + + + + + 1 + 4 + + + 1 + 5 + + + + + 1 + 6 + + + 1 + 7 + + + 2 + 6 + +
+
diff --git a/tests/functions_tricky_update/fixtures/duplicates.xml b/tests/functions_tricky_update/fixtures/topics_watch_duplicates.xml similarity index 100% rename from tests/functions_tricky_update/fixtures/duplicates.xml rename to tests/functions_tricky_update/fixtures/topics_watch_duplicates.xml diff --git a/tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php b/tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php index 4849605e9c..6142997408 100644 --- a/tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php +++ b/tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php @@ -13,7 +13,7 @@ class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_cas { public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/duplicates.xml'); + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/bookmarks_duplicates.xml'); } public static function fixture_data() @@ -57,10 +57,10 @@ class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_cas { $db = $this->new_dbal(); - phpbb_update_rows_avoiding_duplicates($db, TOPICS_WATCH_TABLE, 'topic_id', $from, $to); + phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', $from, $to); $sql = 'SELECT COUNT(*) AS remaining_rows - FROM ' . TOPICS_WATCH_TABLE . ' + FROM ' . BOOKMARKS_TABLE . ' WHERE topic_id = ' . (int) $to; $result = $db->sql_query($sql); $result_count = $db->sql_fetchfield('remaining_rows'); From 6872104aa95a9f2aad565189e25bbf54abc3ca2c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 00:07:01 -0500 Subject: [PATCH 15/34] [ticket/11162] Account for notify_status. PHPBB3-11162 --- phpBB/includes/functions_tricky_update.php | 111 +++++++++++++++++- .../fixtures/topics_watch_duplicates.xml | 38 ++++-- ...avoiding_duplicates_notify_status_test.php | 100 ++++++++++++++++ 3 files changed, 239 insertions(+), 10 deletions(-) create mode 100644 tests/functions_tricky_update/update_rows_avoiding_duplicates_notify_status_test.php diff --git a/phpBB/includes/functions_tricky_update.php b/phpBB/includes/functions_tricky_update.php index a5b9fdacd0..cf922d7014 100644 --- a/phpBB/includes/functions_tricky_update.php +++ b/phpBB/includes/functions_tricky_update.php @@ -20,7 +20,7 @@ if (!defined('IN_PHPBB')) * If this results in rows violating uniqueness constraints, the duplicate * rows are eliminated. * -* The only supported tables are bookmarks and topics_watch. +* The only supported table is bookmarks. * * @param dbal $db Database object * @param string $table Table on which to perform the update @@ -67,7 +67,7 @@ function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_value if (empty($new_user_ids)) { $sql = "UPDATE $table - SET $column = " . (int) $to_value. " + SET $column = " . (int) $to_value . " WHERE $column = '" . $db->sql_escape($from_value) . "'"; $queries[] = $sql; } @@ -77,7 +77,7 @@ function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_value if (!empty($different_user_ids)) { $sql = "UPDATE $table - SET $column = " . (int) $to_value. " + SET $column = " . (int) $to_value . " WHERE $column = '" . $db->sql_escape($from_value) . "' AND " . $db->sql_in_set('user_id', $different_user_ids); $queries[] = $sql; @@ -101,3 +101,108 @@ function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_value $db->sql_transaction('commit'); } } + +/** +* Updates rows in given table from a set of values to a new value. +* If this results in rows violating uniqueness constraints, the duplicate +* rows are merged respecting notify_status (0 takes precedence over 1). +* +* The only supported table is topics_watch. +* +* @param dbal $db Database object +* @param string $table Table on which to perform the update +* @param string $column Column whose values to change +* @param array $from_values An array of values that should be changed +* @param int $to_value The new value +* @return null +*/ +function phpbb_update_rows_avoiding_duplicates_notify_status($db, $table, $column, $from_values, $to_value) +{ + $sql = "SELECT $column, user_id, notify_status + FROM $table + WHERE " . $db->sql_in_set($column, $from_values); + $result = $db->sql_query($sql); + + $old_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $old_user_ids[(int) $row['notify_status']][$row[$column]][] = $row['user_id']; + } + $db->sql_freeresult($result); + + $sql = "SELECT $column, user_id + FROM $table + WHERE $column = '" . (int) $to_value . "'"; + $result = $db->sql_query($sql); + + $new_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $new_user_ids[$row[$column]][] = $row['user_id']; + } + $db->sql_freeresult($result); + + $queries = array(); + $any_found = false; + $extra_updates = array( + 0 => 'notify_status = 0', + 1 => '', + ); + foreach ($from_values as $from_value) + { + foreach ($extra_updates as $notify_status => $extra_update) { + if (!isset($old_user_ids[$notify_status][$from_value])) + { + continue; + } + $any_found = true; + if (empty($new_user_ids)) + { + $sql = "UPDATE $table + SET $column = " . (int) $to_value . " + WHERE $column = '" . $db->sql_escape($from_value) . "'"; + $queries[] = $sql; + } + else + { + $different_user_ids = array_diff($old_user_ids[$notify_status][$from_value], $new_user_ids[$to_value]); + if (!empty($different_user_ids)) + { + $sql = "UPDATE $table + SET $column = " . (int) $to_value . " + WHERE $column = '" . $db->sql_escape($from_value) . "' + AND " . $db->sql_in_set('user_id', $different_user_ids); + $queries[] = $sql; + } + + if ($extra_update) { + $same_user_ids = array_diff($old_user_ids[$notify_status][$from_value], $different_user_ids); + if (!empty($same_user_ids)) + { + $sql = "UPDATE $table + SET $extra_update + WHERE $column = '" . (int) $to_value . "' + AND " . $db->sql_in_set('user_id', $same_user_ids); + $queries[] = $sql; + } + } + } + } + } + + if ($any_found) + { + $db->sql_transaction('begin'); + + foreach ($queries as $sql) + { + $db->sql_query($sql); + } + + $sql = "DELETE FROM $table + WHERE " . $db->sql_in_set($column, $from_values); + $db->sql_query($sql); + + $db->sql_transaction('commit'); + } +} diff --git a/tests/functions_tricky_update/fixtures/topics_watch_duplicates.xml b/tests/functions_tricky_update/fixtures/topics_watch_duplicates.xml index bc08016a8f..c387bb737a 100644 --- a/tests/functions_tricky_update/fixtures/topics_watch_duplicates.xml +++ b/tests/functions_tricky_update/fixtures/topics_watch_duplicates.xml @@ -14,17 +14,17 @@ - 2 + 1 2 1 + 2 3 - 3 - 1 + 0 - + 1 4 @@ -36,20 +36,44 @@ 1 - + 1 6 - 1 + 0 1 7 1 + + + + 1 + 8 + 1 + + + 1 + 9 + 0 + + + + + 1 + 10 + 0 + + + 1 + 11 + 1 + 2 - 6 + 10 1 diff --git a/tests/functions_tricky_update/update_rows_avoiding_duplicates_notify_status_test.php b/tests/functions_tricky_update/update_rows_avoiding_duplicates_notify_status_test.php new file mode 100644 index 0000000000..aa739c5f04 --- /dev/null +++ b/tests/functions_tricky_update/update_rows_avoiding_duplicates_notify_status_test.php @@ -0,0 +1,100 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/topics_watch_duplicates.xml'); + } + + public static function fixture_data() + { + return array( + // description + // from array + // to value + // expected count with to value post update + // expected notify_status values + array( + 'trivial', + array(1), + 1000, + 1, + 1, + ), + array( + 'no conflict', + array(2), + 3, + 2, + 1, + ), + array( + 'conflict, same notify status', + array(4), + 5, + 1, + 1, + ), + array( + 'conflict, notify status 0 into 1', + array(6), + 7, + 1, + 0, + ), + array( + 'conflict, notify status 1 into 0', + array(8), + 9, + 1, + 0, + ), + array( + 'conflict and no conflict', + array(10), + 11, + 2, + 0, + ), + ); + } + + /** + * @dataProvider fixture_data + */ + public function test_update($description, $from, $to, $expected_result_count, $expected_notify_status) + { + $db = $this->new_dbal(); + + phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $from, $to); + + $sql = 'SELECT COUNT(*) AS remaining_rows + FROM ' . TOPICS_WATCH_TABLE . ' + WHERE topic_id = ' . (int) $to; + $result = $db->sql_query($sql); + $result_count = $db->sql_fetchfield('remaining_rows'); + $db->sql_freeresult($result); + + $this->assertEquals($expected_result_count, $result_count); + + // user id of 1 is the user being updated + $sql = 'SELECT notify_status + FROM ' . TOPICS_WATCH_TABLE . ' + WHERE topic_id = ' . (int) $to . ' AND user_id = 1'; + $result = $db->sql_query($sql); + $notify_status = $db->sql_fetchfield('notify_status'); + $db->sql_freeresult($result); + + $this->assertEquals($expected_notify_status, $notify_status); + } +} From 1a411c5658da769e28b03332ed618d5e701dab79 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 00:10:02 -0500 Subject: [PATCH 16/34] [ticket/11162] Use correct functions. PHPBB3-11162 --- phpBB/includes/mcp/mcp_forum.php | 4 ++-- phpBB/includes/mcp/mcp_topic.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 3603224735..cd938e83a0 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -415,11 +415,11 @@ function merge_topics($forum_id, $topic_ids, $to_topic_id) $success_msg = 'POSTS_MERGED_SUCCESS'; // Update the topic watch table. - if (!function_exists('phpbb_update_rows_avoiding_duplicates')) + if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status')) { include($phpbb_root_path . 'includes/functions_tricky_update.' . $phpEx); } - phpbb_update_rows_avoiding_duplicates($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); + phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); // Link to the new topic $return_link .= (($return_link) ? '

' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '', ''); diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index 1fb3cb9d73..29dabdd2a2 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -620,11 +620,11 @@ function merge_posts($topic_id, $to_topic_id) else { // If the topic no longer exist, we will update the topic watch table. - if (!function_exists('phpbb_update_rows_avoiding_duplicates')) + if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status')) { include($phpbb_root_path . 'includes/functions_tricky_update.' . $phpEx); } - phpbb_update_rows_avoiding_duplicates($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); + phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); } // Link to the new topic From 94ebc5707836d931e24e77f5ce1b3a16d0410fb8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 10:40:42 -0500 Subject: [PATCH 17/34] [ticket/11162] Newlines to LF. PHPBB3-11162 --- phpBB/includes/functions_tricky_update.php | 416 ++++++++++----------- 1 file changed, 208 insertions(+), 208 deletions(-) diff --git a/phpBB/includes/functions_tricky_update.php b/phpBB/includes/functions_tricky_update.php index cf922d7014..c8fcb9b6f0 100644 --- a/phpBB/includes/functions_tricky_update.php +++ b/phpBB/includes/functions_tricky_update.php @@ -1,208 +1,208 @@ -sql_in_set($column, $from_values); - $result = $db->sql_query($sql); - - $old_user_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $old_user_ids[$row[$column]][] = $row['user_id']; - } - $db->sql_freeresult($result); - - $sql = "SELECT $column, user_id - FROM $table - WHERE $column = '" . (int) $to_value . "'"; - $result = $db->sql_query($sql); - - $new_user_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $new_user_ids[$row[$column]][] = $row['user_id']; - } - $db->sql_freeresult($result); - - $queries = array(); - $any_found = false; - foreach ($from_values as $from_value) - { - if (!isset($old_user_ids[$from_value])) - { - continue; - } - $any_found = true; - if (empty($new_user_ids)) - { - $sql = "UPDATE $table - SET $column = " . (int) $to_value . " - WHERE $column = '" . $db->sql_escape($from_value) . "'"; - $queries[] = $sql; - } - else - { - $different_user_ids = array_diff($old_user_ids[$from_value], $new_user_ids[$to_value]); - if (!empty($different_user_ids)) - { - $sql = "UPDATE $table - SET $column = " . (int) $to_value . " - WHERE $column = '" . $db->sql_escape($from_value) . "' - AND " . $db->sql_in_set('user_id', $different_user_ids); - $queries[] = $sql; - } - } - } - - if ($any_found) - { - $db->sql_transaction('begin'); - - foreach ($queries as $sql) - { - $db->sql_query($sql); - } - - $sql = "DELETE FROM $table - WHERE " . $db->sql_in_set($column, $from_values); - $db->sql_query($sql); - - $db->sql_transaction('commit'); - } -} - -/** -* Updates rows in given table from a set of values to a new value. -* If this results in rows violating uniqueness constraints, the duplicate -* rows are merged respecting notify_status (0 takes precedence over 1). -* -* The only supported table is topics_watch. -* -* @param dbal $db Database object -* @param string $table Table on which to perform the update -* @param string $column Column whose values to change -* @param array $from_values An array of values that should be changed -* @param int $to_value The new value -* @return null -*/ -function phpbb_update_rows_avoiding_duplicates_notify_status($db, $table, $column, $from_values, $to_value) -{ - $sql = "SELECT $column, user_id, notify_status - FROM $table - WHERE " . $db->sql_in_set($column, $from_values); - $result = $db->sql_query($sql); - - $old_user_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $old_user_ids[(int) $row['notify_status']][$row[$column]][] = $row['user_id']; - } - $db->sql_freeresult($result); - - $sql = "SELECT $column, user_id - FROM $table - WHERE $column = '" . (int) $to_value . "'"; - $result = $db->sql_query($sql); - - $new_user_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $new_user_ids[$row[$column]][] = $row['user_id']; - } - $db->sql_freeresult($result); - - $queries = array(); - $any_found = false; - $extra_updates = array( - 0 => 'notify_status = 0', - 1 => '', - ); - foreach ($from_values as $from_value) - { - foreach ($extra_updates as $notify_status => $extra_update) { - if (!isset($old_user_ids[$notify_status][$from_value])) - { - continue; - } - $any_found = true; - if (empty($new_user_ids)) - { - $sql = "UPDATE $table - SET $column = " . (int) $to_value . " - WHERE $column = '" . $db->sql_escape($from_value) . "'"; - $queries[] = $sql; - } - else - { - $different_user_ids = array_diff($old_user_ids[$notify_status][$from_value], $new_user_ids[$to_value]); - if (!empty($different_user_ids)) - { - $sql = "UPDATE $table - SET $column = " . (int) $to_value . " - WHERE $column = '" . $db->sql_escape($from_value) . "' - AND " . $db->sql_in_set('user_id', $different_user_ids); - $queries[] = $sql; - } - - if ($extra_update) { - $same_user_ids = array_diff($old_user_ids[$notify_status][$from_value], $different_user_ids); - if (!empty($same_user_ids)) - { - $sql = "UPDATE $table - SET $extra_update - WHERE $column = '" . (int) $to_value . "' - AND " . $db->sql_in_set('user_id', $same_user_ids); - $queries[] = $sql; - } - } - } - } - } - - if ($any_found) - { - $db->sql_transaction('begin'); - - foreach ($queries as $sql) - { - $db->sql_query($sql); - } - - $sql = "DELETE FROM $table - WHERE " . $db->sql_in_set($column, $from_values); - $db->sql_query($sql); - - $db->sql_transaction('commit'); - } -} +sql_in_set($column, $from_values); + $result = $db->sql_query($sql); + + $old_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $old_user_ids[$row[$column]][] = $row['user_id']; + } + $db->sql_freeresult($result); + + $sql = "SELECT $column, user_id + FROM $table + WHERE $column = '" . (int) $to_value . "'"; + $result = $db->sql_query($sql); + + $new_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $new_user_ids[$row[$column]][] = $row['user_id']; + } + $db->sql_freeresult($result); + + $queries = array(); + $any_found = false; + foreach ($from_values as $from_value) + { + if (!isset($old_user_ids[$from_value])) + { + continue; + } + $any_found = true; + if (empty($new_user_ids)) + { + $sql = "UPDATE $table + SET $column = " . (int) $to_value . " + WHERE $column = '" . $db->sql_escape($from_value) . "'"; + $queries[] = $sql; + } + else + { + $different_user_ids = array_diff($old_user_ids[$from_value], $new_user_ids[$to_value]); + if (!empty($different_user_ids)) + { + $sql = "UPDATE $table + SET $column = " . (int) $to_value . " + WHERE $column = '" . $db->sql_escape($from_value) . "' + AND " . $db->sql_in_set('user_id', $different_user_ids); + $queries[] = $sql; + } + } + } + + if ($any_found) + { + $db->sql_transaction('begin'); + + foreach ($queries as $sql) + { + $db->sql_query($sql); + } + + $sql = "DELETE FROM $table + WHERE " . $db->sql_in_set($column, $from_values); + $db->sql_query($sql); + + $db->sql_transaction('commit'); + } +} + +/** +* Updates rows in given table from a set of values to a new value. +* If this results in rows violating uniqueness constraints, the duplicate +* rows are merged respecting notify_status (0 takes precedence over 1). +* +* The only supported table is topics_watch. +* +* @param dbal $db Database object +* @param string $table Table on which to perform the update +* @param string $column Column whose values to change +* @param array $from_values An array of values that should be changed +* @param int $to_value The new value +* @return null +*/ +function phpbb_update_rows_avoiding_duplicates_notify_status($db, $table, $column, $from_values, $to_value) +{ + $sql = "SELECT $column, user_id, notify_status + FROM $table + WHERE " . $db->sql_in_set($column, $from_values); + $result = $db->sql_query($sql); + + $old_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $old_user_ids[(int) $row['notify_status']][$row[$column]][] = $row['user_id']; + } + $db->sql_freeresult($result); + + $sql = "SELECT $column, user_id + FROM $table + WHERE $column = '" . (int) $to_value . "'"; + $result = $db->sql_query($sql); + + $new_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $new_user_ids[$row[$column]][] = $row['user_id']; + } + $db->sql_freeresult($result); + + $queries = array(); + $any_found = false; + $extra_updates = array( + 0 => 'notify_status = 0', + 1 => '', + ); + foreach ($from_values as $from_value) + { + foreach ($extra_updates as $notify_status => $extra_update) { + if (!isset($old_user_ids[$notify_status][$from_value])) + { + continue; + } + $any_found = true; + if (empty($new_user_ids)) + { + $sql = "UPDATE $table + SET $column = " . (int) $to_value . " + WHERE $column = '" . $db->sql_escape($from_value) . "'"; + $queries[] = $sql; + } + else + { + $different_user_ids = array_diff($old_user_ids[$notify_status][$from_value], $new_user_ids[$to_value]); + if (!empty($different_user_ids)) + { + $sql = "UPDATE $table + SET $column = " . (int) $to_value . " + WHERE $column = '" . $db->sql_escape($from_value) . "' + AND " . $db->sql_in_set('user_id', $different_user_ids); + $queries[] = $sql; + } + + if ($extra_update) { + $same_user_ids = array_diff($old_user_ids[$notify_status][$from_value], $different_user_ids); + if (!empty($same_user_ids)) + { + $sql = "UPDATE $table + SET $extra_update + WHERE $column = '" . (int) $to_value . "' + AND " . $db->sql_in_set('user_id', $same_user_ids); + $queries[] = $sql; + } + } + } + } + } + + if ($any_found) + { + $db->sql_transaction('begin'); + + foreach ($queries as $sql) + { + $db->sql_query($sql); + } + + $sql = "DELETE FROM $table + WHERE " . $db->sql_in_set($column, $from_values); + $db->sql_query($sql); + + $db->sql_transaction('commit'); + } +} From 16966f52d37e4ebdca4f3846c81dfa85b193501e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 10:41:08 -0500 Subject: [PATCH 18/34] [ticket/11162] Reformat. PHPBB3-11162 --- phpBB/includes/functions_tricky_update.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_tricky_update.php b/phpBB/includes/functions_tricky_update.php index c8fcb9b6f0..10321618b2 100644 --- a/phpBB/includes/functions_tricky_update.php +++ b/phpBB/includes/functions_tricky_update.php @@ -150,7 +150,8 @@ function phpbb_update_rows_avoiding_duplicates_notify_status($db, $table, $colum ); foreach ($from_values as $from_value) { - foreach ($extra_updates as $notify_status => $extra_update) { + foreach ($extra_updates as $notify_status => $extra_update) + { if (!isset($old_user_ids[$notify_status][$from_value])) { continue; @@ -174,8 +175,9 @@ function phpbb_update_rows_avoiding_duplicates_notify_status($db, $table, $colum AND " . $db->sql_in_set('user_id', $different_user_ids); $queries[] = $sql; } - - if ($extra_update) { + + if ($extra_update) + { $same_user_ids = array_diff($old_user_ids[$notify_status][$from_value], $different_user_ids); if (!empty($same_user_ids)) { From fe87d441eeb54bf5efb56a0f69f42848d9ef53d5 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 10:44:36 -0500 Subject: [PATCH 19/34] [ticket/11162] Review comments fixed. PHPBB3-11162 --- phpBB/includes/functions_tricky_update.php | 12 ++++++------ ...e_rows_avoiding_duplicates_notify_status_test.php | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/functions_tricky_update.php b/phpBB/includes/functions_tricky_update.php index 10321618b2..05cb65e68d 100644 --- a/phpBB/includes/functions_tricky_update.php +++ b/phpBB/includes/functions_tricky_update.php @@ -39,19 +39,19 @@ function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_value $old_user_ids = array(); while ($row = $db->sql_fetchrow($result)) { - $old_user_ids[$row[$column]][] = $row['user_id']; + $old_user_ids[$row[$column]][] = (int) $row['user_id']; } $db->sql_freeresult($result); $sql = "SELECT $column, user_id FROM $table - WHERE $column = '" . (int) $to_value . "'"; + WHERE $column = " . (int) $to_value; $result = $db->sql_query($sql); $new_user_ids = array(); while ($row = $db->sql_fetchrow($result)) { - $new_user_ids[$row[$column]][] = $row['user_id']; + $new_user_ids[$row[$column]][] = (int) $row['user_id']; } $db->sql_freeresult($result); @@ -126,19 +126,19 @@ function phpbb_update_rows_avoiding_duplicates_notify_status($db, $table, $colum $old_user_ids = array(); while ($row = $db->sql_fetchrow($result)) { - $old_user_ids[(int) $row['notify_status']][$row[$column]][] = $row['user_id']; + $old_user_ids[(int) $row['notify_status']][$row[$column]][] = (int) $row['user_id']; } $db->sql_freeresult($result); $sql = "SELECT $column, user_id FROM $table - WHERE $column = '" . (int) $to_value . "'"; + WHERE $column = " . (int) $to_value; $result = $db->sql_query($sql); $new_user_ids = array(); while ($row = $db->sql_fetchrow($result)) { - $new_user_ids[$row[$column]][] = $row['user_id']; + $new_user_ids[$row[$column]][] = (int) $row['user_id']; } $db->sql_freeresult($result); diff --git a/tests/functions_tricky_update/update_rows_avoiding_duplicates_notify_status_test.php b/tests/functions_tricky_update/update_rows_avoiding_duplicates_notify_status_test.php index aa739c5f04..9052585552 100644 --- a/tests/functions_tricky_update/update_rows_avoiding_duplicates_notify_status_test.php +++ b/tests/functions_tricky_update/update_rows_avoiding_duplicates_notify_status_test.php @@ -90,7 +90,8 @@ class phpbb_update_rows_avoiding_duplicates_notify_status_test extends phpbb_dat // user id of 1 is the user being updated $sql = 'SELECT notify_status FROM ' . TOPICS_WATCH_TABLE . ' - WHERE topic_id = ' . (int) $to . ' AND user_id = 1'; + WHERE topic_id = ' . (int) $to . ' + AND user_id = 1'; $result = $db->sql_query($sql); $notify_status = $db->sql_fetchfield('notify_status'); $db->sql_freeresult($result); From f5de11438c471a76fc5c5f3a4b8c4c29d07ed734 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 10:47:26 -0500 Subject: [PATCH 20/34] [ticket/11162] Use empty($queries). PHPBB3-11162 --- phpBB/includes/functions_tricky_update.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions_tricky_update.php b/phpBB/includes/functions_tricky_update.php index 05cb65e68d..664c246888 100644 --- a/phpBB/includes/functions_tricky_update.php +++ b/phpBB/includes/functions_tricky_update.php @@ -56,14 +56,12 @@ function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_value $db->sql_freeresult($result); $queries = array(); - $any_found = false; foreach ($from_values as $from_value) { if (!isset($old_user_ids[$from_value])) { continue; } - $any_found = true; if (empty($new_user_ids)) { $sql = "UPDATE $table @@ -85,7 +83,7 @@ function phpbb_update_rows_avoiding_duplicates($db, $table, $column, $from_value } } - if ($any_found) + if (!empty($queries)) { $db->sql_transaction('begin'); @@ -143,7 +141,6 @@ function phpbb_update_rows_avoiding_duplicates_notify_status($db, $table, $colum $db->sql_freeresult($result); $queries = array(); - $any_found = false; $extra_updates = array( 0 => 'notify_status = 0', 1 => '', @@ -156,7 +153,6 @@ function phpbb_update_rows_avoiding_duplicates_notify_status($db, $table, $colum { continue; } - $any_found = true; if (empty($new_user_ids)) { $sql = "UPDATE $table @@ -192,7 +188,7 @@ function phpbb_update_rows_avoiding_duplicates_notify_status($db, $table, $colum } } - if ($any_found) + if (!empty($queries)) { $db->sql_transaction('begin'); From e2c67a8e42beefe1631a90feeb2215e2137c944b Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 12 Dec 2012 21:46:38 -0500 Subject: [PATCH 21/34] [ticket/11162] Rename tricky updates to database helper. PHPBB3-11162 --- ...unctions_tricky_update.php => functions_database_helper.php} | 0 phpBB/includes/mcp/mcp_forum.php | 2 +- phpBB/includes/mcp/mcp_topic.php | 2 +- .../fixtures/bookmarks_duplicates.xml | 0 .../fixtures/topics_watch_duplicates.xml | 0 .../update_rows_avoiding_duplicates_notify_status_test.php | 2 +- .../update_rows_avoiding_duplicates_test.php | 2 +- 7 files changed, 4 insertions(+), 4 deletions(-) rename phpBB/includes/{functions_tricky_update.php => functions_database_helper.php} (100%) rename tests/{functions_tricky_update => functions_database_helper}/fixtures/bookmarks_duplicates.xml (100%) rename tests/{functions_tricky_update => functions_database_helper}/fixtures/topics_watch_duplicates.xml (100%) rename tests/{functions_tricky_update => functions_database_helper}/update_rows_avoiding_duplicates_notify_status_test.php (98%) rename tests/{functions_tricky_update => functions_database_helper}/update_rows_avoiding_duplicates_test.php (98%) diff --git a/phpBB/includes/functions_tricky_update.php b/phpBB/includes/functions_database_helper.php similarity index 100% rename from phpBB/includes/functions_tricky_update.php rename to phpBB/includes/functions_database_helper.php diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index cd938e83a0..db9fbd90bd 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -417,7 +417,7 @@ function merge_topics($forum_id, $topic_ids, $to_topic_id) // Update the topic watch table. if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status')) { - include($phpbb_root_path . 'includes/functions_tricky_update.' . $phpEx); + include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx); } phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index 29dabdd2a2..66d0c7a47e 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -622,7 +622,7 @@ function merge_posts($topic_id, $to_topic_id) // If the topic no longer exist, we will update the topic watch table. if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status')) { - include($phpbb_root_path . 'includes/functions_tricky_update.' . $phpEx); + include($phpbb_root_path . 'includes/functions_database_helper.' . $phpEx); } phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); } diff --git a/tests/functions_tricky_update/fixtures/bookmarks_duplicates.xml b/tests/functions_database_helper/fixtures/bookmarks_duplicates.xml similarity index 100% rename from tests/functions_tricky_update/fixtures/bookmarks_duplicates.xml rename to tests/functions_database_helper/fixtures/bookmarks_duplicates.xml diff --git a/tests/functions_tricky_update/fixtures/topics_watch_duplicates.xml b/tests/functions_database_helper/fixtures/topics_watch_duplicates.xml similarity index 100% rename from tests/functions_tricky_update/fixtures/topics_watch_duplicates.xml rename to tests/functions_database_helper/fixtures/topics_watch_duplicates.xml diff --git a/tests/functions_tricky_update/update_rows_avoiding_duplicates_notify_status_test.php b/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php similarity index 98% rename from tests/functions_tricky_update/update_rows_avoiding_duplicates_notify_status_test.php rename to tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php index 9052585552..6c0f2da1e1 100644 --- a/tests/functions_tricky_update/update_rows_avoiding_duplicates_notify_status_test.php +++ b/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_tricky_update.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_database_helper.php'; class phpbb_update_rows_avoiding_duplicates_notify_status_test extends phpbb_database_test_case { diff --git a/tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php b/tests/functions_database_helper/update_rows_avoiding_duplicates_test.php similarity index 98% rename from tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php rename to tests/functions_database_helper/update_rows_avoiding_duplicates_test.php index 6142997408..2f01d29d15 100644 --- a/tests/functions_tricky_update/update_rows_avoiding_duplicates_test.php +++ b/tests/functions_database_helper/update_rows_avoiding_duplicates_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_tricky_update.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_database_helper.php'; class phpbb_update_rows_avoiding_duplicates_test extends phpbb_database_test_case { From a686910958c0ca6eb64c7be10d60d1ebe15999c9 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 13 Dec 2012 03:07:25 -0500 Subject: [PATCH 22/34] [ticket/11162] Reformat. PHPBB3-11162 --- .../update_rows_avoiding_duplicates_notify_status_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php b/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php index 6c0f2da1e1..d4881daf7e 100644 --- a/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php +++ b/tests/functions_database_helper/update_rows_avoiding_duplicates_notify_status_test.php @@ -91,7 +91,7 @@ class phpbb_update_rows_avoiding_duplicates_notify_status_test extends phpbb_dat $sql = 'SELECT notify_status FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $to . ' - AND user_id = 1'; + AND user_id = 1'; $result = $db->sql_query($sql); $notify_status = $db->sql_fetchfield('notify_status'); $db->sql_freeresult($result); From 754dc9c1592001ac4f223358fd708bd338f49fb3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 12:56:42 +0100 Subject: [PATCH 23/34] [ticket/11250] Add parsing tests for our basic bbcodes in simple cases PHPBB3-11250 --- tests/bbcode/parser_test.php | 148 +++++++++++++++++++++++++++++++++-- 1 file changed, 140 insertions(+), 8 deletions(-) diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 8c7fbc7128..697bcde610 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -13,17 +13,149 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase { - public function test_both_passes() + public function string_bbcode_data() { - $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); - - $parser = new phpbb_bbcode_parser(); + return array( + // Default BBCodes from in their simplest way + array( + 'Test default bbcodes: simple bold', + '[b]bold[/b]', + '[b:]bold[/b:]', + ), + array( + 'Test default bbcodes: simple underlined', + '[u]underlined[/u]', + '[u:]underlined[/u:]', + ), + array( + 'Test default bbcodes: simple italic', + '[i]italic[/i]', + '[i:]italic[/i:]', + ), + array( + 'Test default bbcodes: simple color rgb', + '[color=#FF0000]colored[/color]', + '[color=#FF0000:]colored[/color:]', + ), + array( + 'Test default bbcodes: simple color name', + '[color=red]colored[/color]', + '[color=red:]colored[/color:]', + ), + array( + 'Test default bbcodes: simple quote', + '[quote]quoted[/quote]', + '[quote:]quoted[/quote:]', + ), + array( + 'Test default bbcodes: simple quote with username', + '[quote="username"]quoted[/quote]', + '[quote="username":]quoted[/quote:]', + ), + array( + 'Test default bbcodes: simple code', + '[code]unparsed code[/code]', + '[code:]unparsed code[/code:]', + ), + array( + 'Test default bbcodes: simple php code', + '[code=php]unparsed code[/code]', + '[code=php:]unparsed code[/code:]', + ), + array( + 'Test default bbcodes: simple list', + '[list]no item[/list]', + '[list:]no item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item only', + '[*]unparsed', + '[*]unparsed', + ), + array( + 'Test default bbcodes: simple list-item', + '[list][*]item[/list]', + '[list:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item closed', + '[list][*]item[/*][/list]', + '[list:][*:]item[/*:][/list:]', + ), + array( + 'Test default bbcodes: simple list-item numbered', + '[list=1][*]item[/list]', + '[list=1:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item alpha', + '[list=a][*]item[/list]', + '[list=a:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item roman', + '[list=i][*]item[/list]', + '[list=i:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item disc', + '[list=disc][*]item[/list]', + '[list=disc:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item circle', + '[list=circle][*]item[/list]', + '[list=circle:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item square', + '[list=square][*]item[/list]', + '[list=square:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple img', + '[img]https://area51.phpbb.com/images/area51.png[/img]', + '[img:]https://area51.phpbb.com/images/area51.png[/img:]', + ), + array( + 'Test default bbcodes: simple url', + '[url]https://area51.phpbb.com/[/url]', + '[url:]https://area51.phpbb.com/[/url:]', + ), + array( + 'Test default bbcodes: simple url with description', + '[url=https://area51.phpbb.com/]Area51[/url]', + '[url=https://area51.phpbb.com/:]Area51[/url:]', + ), + array( + 'Test default bbcodes: simple email', + '[email]bbcode-test@phpbb.com[/email]', + '[email:]bbcode-test@phpbb.com[/email:]', + ), + array( + 'Test default bbcodes: simple email with description', + '[email=bbcode-test@phpbb.com]Email[/email]', + '[email=bbcode-test@phpbb.com:]Email[/email:]', + ), + ); + } - $result = $parser->first_pass('[i]Italic [u]underlined text[/u][/i]'); - $result = $parser->second_pass($result); - $expected = 'Italic underlined text'; + /** + * @dataProvider string_bbcode_data + */ + public function test_firstpass($description, $message, $expected) + { + $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); - $this->assertEquals($expected, $result, 'Simple nested BBCode first+second pass'); + global $user, $request; + $user = new phpbb_mock_user; + $request = new phpbb_mock_request; + + $bbcode = new bbcode_firstpass(); + $bbcode->message = $message; + $bbcode->bbcode_init(false); + $bbcode->parse_bbcode(); + $this->assertEquals($expected, $bbcode->message); } } From ade9f831aa151de428c4d2b33fce48f9733db336 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 12:58:57 +0100 Subject: [PATCH 24/34] [ticket/11250] Move quote special cases from class to unit tests PHPBB3-11250 --- phpBB/includes/message_parser.php | 11 ----------- tests/bbcode/parser_test.php | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 1cd2a46fa1..44960dd78d 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -702,17 +702,6 @@ class bbcode_firstpass extends bbcode { global $config, $user; - /** - * If you change this code, make sure the cases described within the following reports are still working: - * #3572 - [quote="[test]test"]test [ test[/quote] - (correct: parsed) - * #14667 - [quote]test[/quote] test ] and [ test [quote]test[/quote] (correct: parsed) - * #14770 - [quote="["]test[/quote] (correct: parsed) - * [quote="[i]test[/i]"]test[/quote] (correct: parsed) - * [quote="[quote]test[/quote]"]test[/quote] (correct: parsed - Username displayed as [quote]test[/quote]) - * #20735 - [quote]test[/[/b]quote] test [/quote][/quote] test - (correct: quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted) - * #40565 - [quote="a"]a[/quote][quote="a]a[/quote] (correct: first quote tag parsed, second quote tag unparsed) - */ - $in = str_replace("\r\n", "\n", str_replace('\"', '"', trim($in))); if (!$in) diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 697bcde610..410eeabe92 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -137,6 +137,32 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[email=bbcode-test@phpbb.com]Email[/email]', '[email=bbcode-test@phpbb.com:]Email[/email:]', ), + + array( + 'PHPBB3-1401 - correct: parsed', + '[quote="[test]test"]test [ test[/quote]', + '[quote="[test]test":]test [ test[/quote:]', + ), + array( + 'PHPBB3-6117 - correct: parsed', + '[quote]test[/quote] test ] and [ test [quote]test[/quote]', + '[quote:]test[/quote:] test ] and [ test [quote:]test[/quote:]', + ), + array( + 'PHPBB3-6200 - correct: parsed', + '[quote="["]test[/quote]', + '[quote="[":]test[/quote:]', + ), + array( + 'PHPBB3-9364 - quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted', + '[quote]test[/[/b]quote] test [/quote][/quote] test', + '[quote:]test[/[/b]quote] test [/quote:][/quote] test', + ), + array( + 'PHPBB3-8096 - first quote tag parsed, second quote tag unparsed', + '[quote="a"]a[/quote][quote="a]a[/quote]', + '[quote="a":]a[/quote:][quote="a]a[/quote]', + ), ); } From deceeb737335b0724c9a15c1f7332ec6deddc3f3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 13:00:14 +0100 Subject: [PATCH 25/34] [ticket/11250] Add some more tests for quotes PHPBB3-11250 --- tests/bbcode/parser_test.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 410eeabe92..f700177498 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -163,6 +163,32 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[quote="a"]a[/quote][quote="a]a[/quote]', '[quote="a":]a[/quote:][quote="a]a[/quote]', ), + + array( + 'Allow textual BBcodes in usernames', + '[quote="[i]test[/i]"]test[/quote]', + '[quote="[i:]test[/i:]":]test[/quote:]', + ), + array( + 'Allow links BBcodes in usernames', + '[quote="[url=http://www.phpbb.com/]test[/url]"]test[/quote]', + '[quote="[url=http://www.phpbb.com/:]test[/url:]":]test[/quote:]', + ), + array( + 'Disallow img BBcodes in usernames - Username displayed as [img]http://www.phpbb.com/[/img]', + '[quote="[img]http://www.phpbb.com/[/img]"]test[/quote]', + '[quote="[img]http://www.phpbb.com/[/img]":]test[/quote:]', + ), + array( + 'Disallow flash BBcodes in usernames - Username displayed as [flash]http://www.phpbb.com/[/flash]', + '[quote="[flash]http://www.phpbb.com/[/flash]"]test[/quote]', + '[quote="[flash]http://www.phpbb.com/[/flash]":]test[/quote:]', + ), + array( + 'parsed - Username displayed as [quote]test[/quote]', + '[quote="[quote]test[/quote]"]test[/quote]', + '[quote="[quote]test[/quote]":]test[/quote:]', + ), ); } From 90a81a064bd119792a2848c3699d1f1ec0ad1827 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 13:03:10 +0100 Subject: [PATCH 26/34] [ticket/11250] Add some comments and fix a description PHPBB3-11250 --- tests/bbcode/parser_test.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index f700177498..ed55a69640 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -2,15 +2,11 @@ /** * * @package testing -* @version $Id$ -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2012 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -// require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode/bbcode_parser_base.php'; -// require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode/bbcode_parser.php'; - class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase { public function string_bbcode_data() @@ -138,6 +134,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[email=bbcode-test@phpbb.com:]Email[/email:]', ), + // Special cases for quote which were reported as bugs before array( 'PHPBB3-1401 - correct: parsed', '[quote="[test]test"]test [ test[/quote]', @@ -164,6 +161,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[quote="a":]a[/quote:][quote="a]a[/quote]', ), + // Nesting bbcodes into quote usernames array( 'Allow textual BBcodes in usernames', '[quote="[i]test[/i]"]test[/quote]', @@ -185,7 +183,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[quote="[flash]http://www.phpbb.com/[/flash]":]test[/quote:]', ), array( - 'parsed - Username displayed as [quote]test[/quote]', + 'Disallow quote BBcodes in usernames - Username displayed as [quote]test[/quote]', '[quote="[quote]test[/quote]"]test[/quote]', '[quote="[quote]test[/quote]":]test[/quote:]', ), From bf312b529384890e1e45a0b073277156b5ab4c5b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 13:04:44 +0100 Subject: [PATCH 27/34] [ticket/11250] Fix method names PHPBB3-11250 --- tests/bbcode/parser_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index ed55a69640..8f0aeab386 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -9,7 +9,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase { - public function string_bbcode_data() + public function bbcode_firstpass_data() { return array( // Default BBCodes from in their simplest way @@ -192,9 +192,9 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase /** - * @dataProvider string_bbcode_data + * @dataProvider bbcode_firstpass_data */ - public function test_firstpass($description, $message, $expected) + public function test_bbcode_firstpass($description, $message, $expected) { $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); From cce821f99d1ad83b029c31baf84328d257cced23 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 13:09:05 +0100 Subject: [PATCH 28/34] [ticket/11250] Add tests for size and attachment PHPBB3-11250 --- tests/bbcode/parser_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 8f0aeab386..32e23236f6 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -38,6 +38,11 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[color=red]colored[/color]', '[color=red:]colored[/color:]', ), + array( + 'Test default bbcodes: simple size', + '[size=75]smaller[/size]', + '[size=75:]smaller[/size:]', + ), array( 'Test default bbcodes: simple quote', '[quote]quoted[/quote]', @@ -133,6 +138,11 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[email=bbcode-test@phpbb.com]Email[/email]', '[email=bbcode-test@phpbb.com:]Email[/email:]', ), + array( + 'Test default bbcodes: simple attachment', + '[attachment=0]filename[/attachment]', + '[attachment=0:]filename[/attachment:]', + ), // Special cases for quote which were reported as bugs before array( From 1e5da1417ad051a16383c967488d88394b3698ae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 13:58:39 +0100 Subject: [PATCH 29/34] [ticket/11250] Fix parsing result with special chars : . and [ are replaced by their html representation if they are text only PHPBB3-11250 --- tests/bbcode/parser_test.php | 75 +++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 32e23236f6..0e1f405bae 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -7,6 +7,11 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php'; + class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase { public function bbcode_firstpass_data() @@ -50,8 +55,8 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase ), array( 'Test default bbcodes: simple quote with username', - '[quote="username"]quoted[/quote]', - '[quote="username":]quoted[/quote:]', + '[quote="username"]quoted[/quote]', + '[quote="username":]quoted[/quote:]', ), array( 'Test default bbcodes: simple code', @@ -61,12 +66,12 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase array( 'Test default bbcodes: simple php code', '[code=php]unparsed code[/code]', - '[code=php:]unparsed code[/code:]', + '[code=php:]unparsed code[/code:]', ), array( 'Test default bbcodes: simple list', '[list]no item[/list]', - '[list:]no item[/list:]', + '[list:]no item[/list:u:]', ), array( 'Test default bbcodes: simple list-item only', @@ -76,79 +81,79 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase array( 'Test default bbcodes: simple list-item', '[list][*]item[/list]', - '[list:][*:]item[/list:]', + '[list:][*:]item[/*:m:][/list:u:]', ), array( 'Test default bbcodes: simple list-item closed', '[list][*]item[/*][/list]', - '[list:][*:]item[/*:][/list:]', + '[list:][*:]item[/*:][/list:u:]', ), array( 'Test default bbcodes: simple list-item numbered', '[list=1][*]item[/list]', - '[list=1:][*:]item[/list:]', + '[list=1:][*:]item[/*:m:][/list:o:]', ), array( 'Test default bbcodes: simple list-item alpha', '[list=a][*]item[/list]', - '[list=a:][*:]item[/list:]', + '[list=a:][*:]item[/*:m:][/list:o:]', ), array( 'Test default bbcodes: simple list-item roman', '[list=i][*]item[/list]', - '[list=i:][*:]item[/list:]', + '[list=i:][*:]item[/*:m:][/list:o:]', ), array( 'Test default bbcodes: simple list-item disc', '[list=disc][*]item[/list]', - '[list=disc:][*:]item[/list:]', + '[list=disc:][*:]item[/*:m:][/list:u:]', ), array( 'Test default bbcodes: simple list-item circle', '[list=circle][*]item[/list]', - '[list=circle:][*:]item[/list:]', + '[list=circle:][*:]item[/*:m:][/list:u:]', ), array( 'Test default bbcodes: simple list-item square', '[list=square][*]item[/list]', - '[list=square:][*:]item[/list:]', + '[list=square:][*:]item[/*:m:][/list:u:]', ), array( 'Test default bbcodes: simple img', '[img]https://area51.phpbb.com/images/area51.png[/img]', - '[img:]https://area51.phpbb.com/images/area51.png[/img:]', + '[img:]https://area51.phpbb.com/images/area51.png[/img:]', ), array( 'Test default bbcodes: simple url', '[url]https://area51.phpbb.com/[/url]', - '[url:]https://area51.phpbb.com/[/url:]', + '[url:]https://area51.phpbb.com/[/url:]', ), array( 'Test default bbcodes: simple url with description', '[url=https://area51.phpbb.com/]Area51[/url]', - '[url=https://area51.phpbb.com/:]Area51[/url:]', + '[url=https://area51.phpbb.com/:]Area51[/url:]', ), array( 'Test default bbcodes: simple email', '[email]bbcode-test@phpbb.com[/email]', - '[email:]bbcode-test@phpbb.com[/email:]', + '[email:]bbcode-test@phpbb.com[/email:]', ), array( 'Test default bbcodes: simple email with description', '[email=bbcode-test@phpbb.com]Email[/email]', - '[email=bbcode-test@phpbb.com:]Email[/email:]', + '[email=bbcode-test@phpbb.com:]Email[/email:]', ), array( 'Test default bbcodes: simple attachment', '[attachment=0]filename[/attachment]', - '[attachment=0:]filename[/attachment:]', + '[attachment=0:]filename[/attachment:]', ), // Special cases for quote which were reported as bugs before array( 'PHPBB3-1401 - correct: parsed', - '[quote="[test]test"]test [ test[/quote]', - '[quote="[test]test":]test [ test[/quote:]', + '[quote="[test]test"]test [ test[/quote]', + '[quote="[test]test":]test [ test[/quote:]', ), array( 'PHPBB3-6117 - correct: parsed', @@ -157,8 +162,8 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase ), array( 'PHPBB3-6200 - correct: parsed', - '[quote="["]test[/quote]', - '[quote="[":]test[/quote:]', + '[quote="["]test[/quote]', + '[quote="[":]test[/quote:]', ), array( 'PHPBB3-9364 - quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted', @@ -167,35 +172,35 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase ), array( 'PHPBB3-8096 - first quote tag parsed, second quote tag unparsed', - '[quote="a"]a[/quote][quote="a]a[/quote]', - '[quote="a":]a[/quote:][quote="a]a[/quote]', + '[quote="a"]a[/quote][quote="a]a[/quote]', + '[quote="a":]a[/quote:][quote="a]a[/quote]', ), // Nesting bbcodes into quote usernames array( 'Allow textual BBcodes in usernames', - '[quote="[i]test[/i]"]test[/quote]', - '[quote="[i:]test[/i:]":]test[/quote:]', + '[quote="[i]test[/i]"]test[/quote]', + '[quote="[i:]test[/i:]":]test[/quote:]', ), array( 'Allow links BBcodes in usernames', - '[quote="[url=http://www.phpbb.com/]test[/url]"]test[/quote]', - '[quote="[url=http://www.phpbb.com/:]test[/url:]":]test[/quote:]', + '[quote="[url=https://area51.phpbb.com/]test[/url]"]test[/quote]', + '[quote="[url=https://area51.phpbb.com/:]test[/url:]":]test[/quote:]', ), array( - 'Disallow img BBcodes in usernames - Username displayed as [img]http://www.phpbb.com/[/img]', - '[quote="[img]http://www.phpbb.com/[/img]"]test[/quote]', - '[quote="[img]http://www.phpbb.com/[/img]":]test[/quote:]', + 'Allow img BBcodes in usernames - Username displayed the image', + '[quote="[img]https://area51.phpbb.com/images/area51.png[/img]"]test[/quote]', + '[quote="[img:]https://area51.phpbb.com/images/area51.png[/img:]":]test[/quote:]', ), array( 'Disallow flash BBcodes in usernames - Username displayed as [flash]http://www.phpbb.com/[/flash]', - '[quote="[flash]http://www.phpbb.com/[/flash]"]test[/quote]', - '[quote="[flash]http://www.phpbb.com/[/flash]":]test[/quote:]', + '[quote="[flash]http://www.phpbb.com/[/flash]"]test[/quote]', + '[quote="[flash]http://www.phpbb.com/[/flash]":]test[/quote:]', ), array( 'Disallow quote BBcodes in usernames - Username displayed as [quote]test[/quote]', - '[quote="[quote]test[/quote]"]test[/quote]', - '[quote="[quote]test[/quote]":]test[/quote:]', + '[quote="[quote]test[/quote]"]test[/quote]', + '[quote="[quote]test[/quote]":]test[/quote:]', ), ); } From 8bbf3a788fd14a0c9dd67e985d401ce19c1da8a5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 13:59:48 +0100 Subject: [PATCH 30/34] [ticket/11250] Run tests by default and add an option for incomplete ones PHPBB3-11250 --- tests/bbcode/parser_test.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 0e1f405bae..be5cb8524e 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -211,7 +211,10 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase */ public function test_bbcode_firstpass($description, $message, $expected) { - $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); + if ($incomplete) + { + $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); + } global $user, $request; $user = new phpbb_mock_user; From 4f080ba0d66846ced15295cb0813245d54bd1833 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 14:29:11 +0100 Subject: [PATCH 31/34] [ticket/11250] Add tests for simple nesting and code PHPBB3-11250 --- tests/bbcode/parser_test.php | 51 +++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index be5cb8524e..b87c3668a9 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -17,7 +17,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase public function bbcode_firstpass_data() { return array( - // Default BBCodes from in their simplest way + // Default bbcodes from in their simplest way array( 'Test default bbcodes: simple bold', '[b]bold[/b]', @@ -176,32 +176,69 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[quote="a":]a[/quote:][quote="a]a[/quote]', ), + // Simple bbcodes nesting + array( + 'Allow textual bbcodes in textual bbcodes', + '[b]bold [i]bold + italic[/i][/b]', + '[b:]bold [i:]bold + italic[/i:][/b:]', + ), + array( + 'Allow textual bbcodes in url with description', + '[url=https://area51.phpbb.com/]Area51 [i]italic[/i][/url]', + '[url=https://area51.phpbb.com/:]Area51 [i:]italic[/i:][/url:]', + ), + array( + 'Allow url with description in textual bbcodes', + '[i]italic [url=https://area51.phpbb.com/]Area51[/url][/i]', + '[i:]italic [url=https://area51.phpbb.com/:]Area51[/url:][/i:]', + ), + // Nesting bbcodes into quote usernames array( - 'Allow textual BBcodes in usernames', + 'Allow textual bbcodes in usernames', '[quote="[i]test[/i]"]test[/quote]', '[quote="[i:]test[/i:]":]test[/quote:]', ), array( - 'Allow links BBcodes in usernames', + 'Allow links bbcodes in usernames', '[quote="[url=https://area51.phpbb.com/]test[/url]"]test[/quote]', '[quote="[url=https://area51.phpbb.com/:]test[/url:]":]test[/quote:]', ), array( - 'Allow img BBcodes in usernames - Username displayed the image', + 'Allow img bbcodes in usernames - Username displayed the image', '[quote="[img]https://area51.phpbb.com/images/area51.png[/img]"]test[/quote]', '[quote="[img:]https://area51.phpbb.com/images/area51.png[/img:]":]test[/quote:]', ), array( - 'Disallow flash BBcodes in usernames - Username displayed as [flash]http://www.phpbb.com/[/flash]', + 'Disallow flash bbcodes in usernames - Username displayed as [flash]http://www.phpbb.com/[/flash]', '[quote="[flash]http://www.phpbb.com/[/flash]"]test[/quote]', '[quote="[flash]http://www.phpbb.com/[/flash]":]test[/quote:]', ), array( - 'Disallow quote BBcodes in usernames - Username displayed as [quote]test[/quote]', + 'Disallow quote bbcodes in usernames - Username displayed as [quote]test[/quote]', '[quote="[quote]test[/quote]"]test[/quote]', '[quote="[quote]test[/quote]":]test[/quote:]', ), + + // Do not parse bbcodes in code boxes + array( + 'Do not parse textual bbcodes in code', + '[code]unparsed code [b]bold [i]bold + italic[/i][/b][/code]', + '[code:]unparsed code [b]bold [i]bold + italic[/i][/b][/code:]', + ), + array( + 'Do not parse quote bbcodes in code', + '[code]unparsed code [quote="username"]quoted[/quote][/code]', + '[code:]unparsed code [quote="username"]quoted[/quote][/code:]', + ), + + // New user friendly mixed nesting + array( + 'Textual bbcode nesting into textual bbcode', + '[b]bold [i]bold + italic[/b] italic[/i]', + '[b:]bold [i:]bold + italic[/b:] italic[/i:]', + 'Incomplete: secondpass parses as [b:]bold [i:]bold + italic[/i:] italic[/b:]', + ), ); } @@ -209,7 +246,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase /** * @dataProvider bbcode_firstpass_data */ - public function test_bbcode_firstpass($description, $message, $expected) + public function test_bbcode_firstpass($description, $message, $expected, $incomplete = false) { if ($incomplete) { From ebe1f5d8dace9c3899432706f21a8dc8403fc350 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 18:31:12 +0100 Subject: [PATCH 32/34] [ticket/11250] Use user defined message as incomplete message PHPBB3-11250 --- tests/bbcode/parser_test.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index b87c3668a9..d0dcce5bbf 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -237,12 +237,11 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase 'Textual bbcode nesting into textual bbcode', '[b]bold [i]bold + italic[/b] italic[/i]', '[b:]bold [i:]bold + italic[/b:] italic[/i:]', - 'Incomplete: secondpass parses as [b:]bold [i:]bold + italic[/i:] italic[/b:]', + 'Incomplete test case: secondpass parses as [b:]bold [i:]bold + italic[/i:] italic[/b:]', ), ); } - /** * @dataProvider bbcode_firstpass_data */ @@ -250,7 +249,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase { if ($incomplete) { - $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); + $this->markTestIncomplete($incomplete); } global $user, $request; From d1eb3449af5e7675f6896406e78fa1f240d4a3e8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 14 Dec 2012 14:05:46 -0500 Subject: [PATCH 33/34] [ticket/11268] Delete phpbb_db_driver_mysql4 as there is no such thing. PHPBB3-11268 --- tests/test_framework/phpbb_database_test_connection_manager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 4ce5f03a8b..03097a10a0 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -227,7 +227,6 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { case 'phpbb_db_driver_mysql': - case 'phpbb_db_driver_mysql4': case 'phpbb_db_driver_mysqli': $sql = 'SHOW TABLES'; break; From 95bd4d73eb41d677470b0bf77c521ae2a9bb731e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 10:33:03 -0600 Subject: [PATCH 34/34] [ticket/11103] Mark topic/post subscription notification read when approved PHPBB3-11103 --- phpBB/includes/mcp/mcp_queue.php | 14 +++++++++++++- phpBB/includes/notification/manager.php | 10 ---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 2a2146db71..24afa1f210 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -615,7 +615,13 @@ function approve_post($post_id_list, $id, $mode) { $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); - $phpbb_notifications->add_notifications('topic', $post_data); + $phpbb_notifications->add_notifications(array( + 'quote', + 'topic', + ), $post_data); + + $phpbb_notifications->mark_notifications_read('quote', $post_data['post_id'], $user->data['user_id']); + $phpbb_notifications->mark_notifications_read('topic', $post_data['topic_id'], $user->data['user_id']); if ($notify_poster) { @@ -631,6 +637,12 @@ function approve_post($post_id_list, $id, $mode) 'bookmark', 'post', ), $post_data); + + $phpbb_notifications->mark_notifications_read(array( + 'quote', + 'bookmark', + 'post', + ),$post_data['post_id'], $user->data['user_id']); if ($notify_poster) { diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 653446ab73..6bf97a3e71 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -226,16 +226,6 @@ class phpbb_notification_manager */ public function mark_notifications_read($item_type, $item_id, $user_id, $time = false) { - if (is_array($item_type)) - { - foreach ($item_type as $type) - { - $this->mark_notifications_read($type, $item_id, $user_id, $time); - } - - return; - } - $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . $this->notifications_table . "