From 3c7ff1c417bd57ab71057fa3d880d58f1ee65f2a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 30 Jan 2014 22:21:06 +0100 Subject: [PATCH 01/11] [ticket/12150] Add options to acp PHPBB3-12150 --- phpBB/adm/style/acp_forums.html | 13 ++++++ phpBB/includes/acp/acp_forums.php | 3 ++ phpBB/language/en/acp/forums.php | 2 + .../data/v310/prune_shadow_topics.php | 44 +++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php diff --git a/phpBB/adm/style/acp_forums.html b/phpBB/adm/style/acp_forums.html index e8b20007dc..4a534d0592 100644 --- a/phpBB/adm/style/acp_forums.html +++ b/phpBB/adm/style/acp_forums.html @@ -278,6 +278,19 @@
+
+

{L_FORUM_PRUNE_SHADOW_TOPICS_EXPLAIN}
+
+
+
+
+

{L_AUTO_PRUNE_FREQ_EXPLAIN}
+
{L_DAYS}
+
+
+

{L_AUTO_PRUNE_DAYS_EXPLAIN}
+
{L_DAYS}
+
diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index a1af8c489d..4cefc04608 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -457,6 +457,9 @@ class acp_forums 'prune_days' => 7, 'prune_viewed' => 7, 'prune_freq' => 1, + 'enable_shadow_topic_prune' => false, + 'prune_shadow_topic_days' => 7, + 'prune_shadow_topic_freq' => 1, 'forum_flags' => FORUM_FLAG_POST_REVIEW + FORUM_FLAG_ACTIVE_TOPICS, 'forum_options' => 0, 'forum_password' => '', diff --git a/phpBB/language/en/acp/forums.php b/phpBB/language/en/acp/forums.php index 756cb7ae0f..f452dad8a0 100644 --- a/phpBB/language/en/acp/forums.php +++ b/phpBB/language/en/acp/forums.php @@ -101,6 +101,8 @@ $lang = array_merge($lang, array( 'FORUM_PASSWORD_OLD' => 'The forum password is using an old hashing method and should be changed.', 'FORUM_PASSWORD_MISMATCH' => 'The passwords you entered did not match.', 'FORUM_PRUNE_SETTINGS' => 'Forum prune settings', + 'FORUM_PRUNE_SHADOW_TOPICS' => 'Enable auto-pruning of shadow topics', + 'FORUM_PRUNE_SHADOW_TOPICS_EXPLAIN' => 'Prunes the forum of shadow topics, set the frequency/age parameters below.', 'FORUM_RESYNCED' => 'Forum “%s” successfully resynced', 'FORUM_RULES_EXPLAIN' => 'Forum rules are displayed at any page within the given forum.', 'FORUM_RULES_LINK' => 'Link to forum rules', diff --git a/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php b/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php new file mode 100644 index 0000000000..0aca897946 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php @@ -0,0 +1,44 @@ + array( + $this->table_prefix . 'forums' => array( + 'enable_shadow_topic_prune' => array('BOOL', 0, 'after' => 'prune_freq'), + 'prune_shadow_topic_days' => array('UINT', 7, 'after' => 'enable_shadow_topic_prune'), + 'prune_shadow_topic_freq' => array('UINT', 1, 'after' => 'prune_shadow_topic_freq'), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'forums' => array( + 'enable_shadow_topic_prune', + 'prune_shadow_topic_days', + 'prune_shadow_topic_freq', + ), + ), + ); + } +} From a7abf8218dd8440926549df1f5659820f05fd76a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 31 Jan 2014 22:37:27 +0100 Subject: [PATCH 02/11] [ticket/12150] Add prune columns to schema files and migration file PHPBB3-12150 --- phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php b/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php index 0aca897946..0cf9981c14 100644 --- a/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php +++ b/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php @@ -24,6 +24,7 @@ class prune_shadow_topics extends \phpbb\db\migration\migration 'enable_shadow_topic_prune' => array('BOOL', 0, 'after' => 'prune_freq'), 'prune_shadow_topic_days' => array('UINT', 7, 'after' => 'enable_shadow_topic_prune'), 'prune_shadow_topic_freq' => array('UINT', 1, 'after' => 'prune_shadow_topic_freq'), + 'prune_shadow_topic_next' => array('INT:11', 0, 'after' => 'prune_shadow_topic_freq'), ), ), ); From 02fdae4e8800ded878dcdc848563aef202069317 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 31 Jan 2014 23:06:03 +0100 Subject: [PATCH 03/11] [ticket/12150] Add file and caller for pruning shadow topics PHPBB3-12150 --- phpBB/config/cron_tasks.yml | 12 ++ phpBB/includes/functions_admin.php | 5 + phpBB/language/en/acp/common.php | 1 + .../cron/task/core/prune_shadow_topics.php | 188 ++++++++++++++++++ phpBB/viewforum.php | 12 ++ 5 files changed, 218 insertions(+) create mode 100644 phpBB/phpbb/cron/task/core/prune_shadow_topics.php diff --git a/phpBB/config/cron_tasks.yml b/phpBB/config/cron_tasks.yml index fd3aea85dc..3fd049f567 100644 --- a/phpBB/config/cron_tasks.yml +++ b/phpBB/config/cron_tasks.yml @@ -23,6 +23,18 @@ services: tags: - { name: cron.task } + cron.task.core.prune_shadow_topics: + class: phpbb\cron\task\core\prune_shadow_topics + arguments: + - %core.root_path% + - %core.php_ext% + - @config + - @dbal.conn + calls: + - [set_name, [cron.task.core.prune_shadow_topics]] + tags: + - { name: cron.task } + cron.task.core.prune_notifications: class: phpbb\cron\task\core\prune_notifications arguments: diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 81a381b326..a277429c32 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2326,6 +2326,11 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync $sql_and .= " AND topic_last_view_time < $prune_date"; } + if ($prune_mode == 'shadow') + { + $sql_and .= ' AND topic_type = ' . ITEM_MOVED . "AND topic_last_post_time < $prune_date"; + } + $sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_id) . " diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index cf32c7c225..8c748fe463 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -676,6 +676,7 @@ $lang = array_merge($lang, array( 'LOG_PRUNE' => 'Pruned forums
» %s', 'LOG_AUTO_PRUNE' => 'Auto-pruned forums
» %s', + 'LOG_PRUNE_SHADOW_TOPIC' => 'Auto-pruned shadow topics
» %s', 'LOG_PRUNE_USER_DEAC' => 'Users deactivated
» %s', 'LOG_PRUNE_USER_DEL_DEL' => 'Users pruned and posts deleted
» %s', 'LOG_PRUNE_USER_DEL_ANON' => 'Users pruned and posts retained
» %s', diff --git a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php new file mode 100644 index 0000000000..97e3a474c4 --- /dev/null +++ b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php @@ -0,0 +1,188 @@ +phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->config = $config; + $this->db = $db; + } + + /** + * Manually set forum data. + * + * @param array $forum_data Information about a forum to be pruned. + */ + public function set_forum_data($forum_data) + { + $this->forum_data = $forum_data; + } + + /** + * Runs this cron task. + * + * @return null + */ + public function run() + { + if (!function_exists('auto_prune')) + { + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext); + } + + if ($this->forum_data['prune_shadow_topic_days']) + { + auto_prune($this->forum_data['forum_id'], 'shadow', $this->forum_data['forum_flags'], $this->forum_data['prune_shadow_topic_days'], $this->forum_data['prune_shadow_topic_freq']); + } + } + + /** + * Returns whether this cron task can run, given current board configuration. + * + * This cron task will not run when system cron is utilised, as in + * such cases prune_all_forums task would run instead. + * + * Additionally, this task must be given the forum data, either via + * the constructor or parse_parameters method. + * + * @return bool + */ + public function is_runnable() + { + return !$this->config['use_system_cron'] && $this->forum_data; + } + + /** + * Returns whether this cron task should run now, because enough time + * has passed since it was last run. + * + * Forum pruning interval is specified in the forum data. + * + * @return bool + */ + public function should_run() + { + return $this->forum_data['enable_shadow_topic_prune'] && $this->forum_data['prune_shadow_topic_next'] < time(); + } + + /** + * Returns parameters of this cron task as an array. + * The array has one key, f, whose value is id of the forum to be pruned. + * + * @return array + */ + public function get_parameters() + { + return array('f' => $this->forum_data['forum_id']); + } + + /** + * Parses parameters found in $request, which is an instance of + * \phpbb\request\request_interface. + * + * It is expected to have a key f whose value is id of the forum to be pruned. + * + * @param \phpbb\request\request_interface $request Request object. + * + * @return null + */ + public function parse_parameters(\phpbb\request\request_interface $request) + { + $this->forum_data = null; + if ($request->is_set('f')) + { + $forum_id = $request->variable('f', 0); + + $sql = 'SELECT forum_id, prune_shadow_topic_next, enable_shadow_topic_prune, prune_shadow_topic_days, forum_flags, prune_shadow_topic_freq + FROM ' . FORUMS_TABLE . " + WHERE forum_id = $forum_id"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + $this->forum_data = $row; + } + } + } + + /** + * Automatically prune shadow topics + * Based on fuunction auto_prune() + * @param int $forum_id Forum ID of forum that should be pruned + * @param string $prune_mode Prune mode + * @param int $prune_flags Prune flags + * @param int $prune_freq Prune frequency + * @return null + */ + protected function auto_prune_shadow_topics($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_freq) + { + $sql = 'SELECT forum_name + FROM ' . FORUMS_TABLE . " + WHERE forum_id = $forum_id"; + $result = $this->db->sql_query($sql, 3600); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + $prune_date = time() - ($prune_days * 86400); + $next_prune = time() + ($prune_freq * 86400); + + prune($forum_id, $prune_mode, $prune_date, $prune_flags, true); + + $sql = 'UPDATE ' . FORUMS_TABLE . " + SET prune_shadow_topic_next = $next_prune + WHERE forum_id = $forum_id"; + $this->db->sql_query($sql); + + add_log('admin', 'LOG_PRUNE_SHADOW_TOPIC', $row['forum_name']); + } + + return; + } +} diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 7f194bbcef..4da0267284 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -224,6 +224,18 @@ if (!$config['use_system_cron']) $url = $task->get_url(); $template->assign_var('RUN_CRON_TASK', 'cron'); } + else + { + // See if we should prune the shadow topics instead + $task = $cron->find_task('cron.task.core.prune_shadow_topics'); + $task->set_forum_data($forum_data); + + if ($task->is_ready()) + { + $url = $task->get_url(); + $template->assign_var('RUN_CRON_TASK', 'cron'); + } + } } // Forum rules and subscription info From d97c58aeeaf24b6d76e21642e1764b471f212d87 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 2 Feb 2014 12:52:57 +0100 Subject: [PATCH 04/11] [ticket/12150] Add missing prune settings variables in acp_forums PHPBB3-12150 --- phpBB/adm/style/acp_forums.html | 4 ++-- phpBB/includes/acp/acp_forums.php | 6 ++++++ phpBB/phpbb/cron/task/core/prune_shadow_topics.php | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/phpBB/adm/style/acp_forums.html b/phpBB/adm/style/acp_forums.html index 4a534d0592..2e826e7c13 100644 --- a/phpBB/adm/style/acp_forums.html +++ b/phpBB/adm/style/acp_forums.html @@ -280,8 +280,8 @@

{L_FORUM_PRUNE_SHADOW_TOPICS_EXPLAIN}
-
-
+
+

{L_AUTO_PRUNE_FREQ_EXPLAIN}
diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 4cefc04608..4cce7b07ce 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -138,12 +138,15 @@ class acp_forums 'enable_prune' => request_var('enable_prune', false), 'enable_post_review' => request_var('enable_post_review', true), 'enable_quick_reply' => request_var('enable_quick_reply', false), + 'enable_shadow_topic_prune' => request_var('enable_shadow_topic_prune', false), 'prune_days' => request_var('prune_days', 7), 'prune_viewed' => request_var('prune_viewed', 7), 'prune_freq' => request_var('prune_freq', 1), 'prune_old_polls' => request_var('prune_old_polls', false), 'prune_announce' => request_var('prune_announce', false), 'prune_sticky' => request_var('prune_sticky', false), + 'prune_shadow_topic_days' => request_var('prune_shadow_topic_days', 7), + 'prune_shadow_topic_freq' => request_var('prune_shadow_topic_freq', 1), 'forum_password' => request_var('forum_password', '', true), 'forum_password_confirm'=> request_var('forum_password_confirm', '', true), 'forum_password_unset' => request_var('forum_password_unset', false), @@ -639,6 +642,8 @@ class acp_forums 'PRUNE_FREQ' => $forum_data['prune_freq'], 'PRUNE_DAYS' => $forum_data['prune_days'], 'PRUNE_VIEWED' => $forum_data['prune_viewed'], + 'PRUNE_SHADOW_TOPIC_FREQ' => $forum_data['prune_shadow_topic_freq'], + 'PRUNE_SHADOW_TOPIC_DAYS' => $forum_data['prune_shadow_topic_days'], 'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'], 'FORUM_RULES_LINK' => $forum_data['forum_rules_link'], 'FORUM_RULES' => $forum_data['forum_rules'], @@ -671,6 +676,7 @@ class acp_forums 'S_DISPLAY_SUBFORUM_LIST' => ($forum_data['display_subforum_list']) ? true : false, 'S_DISPLAY_ON_INDEX' => ($forum_data['display_on_index']) ? true : false, 'S_PRUNE_ENABLE' => ($forum_data['enable_prune']) ? true : false, + 'S_PRUNE_SHADOW_TOPIC_ENABLE' => ($forum_data['enable_shadow_topic_prune']) ? true : false, 'S_FORUM_LINK_TRACK' => ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false, 'S_PRUNE_OLD_POLLS' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false, 'S_PRUNE_ANNOUNCE' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false, diff --git a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php index 97e3a474c4..4d7166ccb3 100644 --- a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php +++ b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php @@ -75,7 +75,7 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t if ($this->forum_data['prune_shadow_topic_days']) { - auto_prune($this->forum_data['forum_id'], 'shadow', $this->forum_data['forum_flags'], $this->forum_data['prune_shadow_topic_days'], $this->forum_data['prune_shadow_topic_freq']); + $this->auto_prune_shadow_topics($this->forum_data['forum_id'], 'shadow', $this->forum_data['forum_flags'], $this->forum_data['prune_shadow_topic_days'], $this->forum_data['prune_shadow_topic_freq']); } } From 76b7355b8744345700a61fa635d7738f9726875e Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 2 Feb 2014 17:51:05 +0100 Subject: [PATCH 05/11] [ticket/12150] Add missing space to query for shadow topics PHPBB3-12150 --- phpBB/includes/functions_admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index a277429c32..2bf8e6dcf0 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2328,7 +2328,7 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync if ($prune_mode == 'shadow') { - $sql_and .= ' AND topic_type = ' . ITEM_MOVED . "AND topic_last_post_time < $prune_date"; + $sql_and .= ' AND topic_status = ' . ITEM_MOVED . " AND topic_last_post_time < $prune_date"; } $sql = 'SELECT topic_id From 5866f08919f2d48ab9c1b62caf20836f66cdd21f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 2 Feb 2014 17:52:01 +0100 Subject: [PATCH 06/11] [ticket/12150] Add functional tests for pruning shadow topics PHPBB3-12150 --- tests/functional/prune_shadow_topic_test.php | 207 +++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 tests/functional/prune_shadow_topic_test.php diff --git a/tests/functional/prune_shadow_topic_test.php b/tests/functional/prune_shadow_topic_test.php new file mode 100644 index 0000000000..1db8c3aab7 --- /dev/null +++ b/tests/functional/prune_shadow_topic_test.php @@ -0,0 +1,207 @@ +login(); + $this->admin_login(); + + $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => 'Prune Shadow', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + 'enable_shadow_topic_prune' => true, + 'prune_shadow_topic_freq' => 1, + 'prune_shadow_topic_days' => 1, + )); + $crawler = self::submit($form); + } + + public function test_create_post() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Prune Shadow', + ), + )); + + $this->assert_forum_details($this->data['forums']['Prune Shadow'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => 0, + ), 'initial comparison'); + + // Test creating topic + $this->post = $this->create_topic($this->data['forums']['Prune Shadow'], 'Prune Shadow #1', 'This is a test topic posted by the testing framework.'); + $crawler = self::request('GET', "viewtopic.php?t={$this->post['topic_id']}&sid={$this->sid}"); + + $this->assertContains('Prune Shadow #1', $crawler->filter('html')->text()); + $this->data['topics']['Prune Shadow #1'] = (int) $post['topic_id']; + $this->data['posts']['Prune Shadow #1'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + + $this->assert_forum_details($this->data['forums']['Prune Shadow'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Prune Shadow #1'], + ), 'after creating topic #1'); + + // Test creating a reply + $post2 = $this->create_post($this->data['forums']['Prune Shadow'], $this->post['topic_id'], 'Re: Prune Shadow #1-#2', 'This is a test post posted by the testing framework.'); + $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); + + $this->assertContains('Re: Prune Shadow #1-#2', $crawler->filter('html')->text()); + $this->data['posts']['Re: Prune Shadow #1-#2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->eq(1)->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); + + $this->assert_forum_details($this->data['forums']['Prune Shadow'], array( + 'forum_posts_approved' => 2, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + 'forum_last_post_id' => $this->data['posts']['Re: Prune Shadow #1-#2'], + ), 'after replying'); + } + + public function test_move_topic() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Prune Shadow', + ), + 'topics' => array( + 'Prune Shadow #1', + ), + )); + + $crawler = self::request('GET', "mcp.php?f={$this->data['forums']['Prune Shadow']}&i=main&action=move&mode=forum_view&start=0&topic_id_list[]={$this->data['topics']['Prune Shadow #1']}&sid={$this->sid}"); + $form = $crawler->selectButton('confirm')->form(array( + 'to_forum_id' => 2, + 'move_leave_shadow' => true, + )); + $crawler = self::submit($form); + + $this->assert_forum_details($this->data['forums']['Prune Shadow'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + ), 'after moving'); + + $this->db = $this->get_db(); + // Date topic 3 days back + $sql = 'UPDATE phpbb_topics + SET topic_last_post_time = ' . (time() - 60*60*24*3) . ' + WHERE topic_id = ' . ($this->data['topics']['Prune Shadow #1'] + 1); + $result = $this->db->sql_query($sql); + + $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Prune Shadow']}&sid={$this->sid}"); + $cron_link = $crawler->filter('img')->last()->attr('src'); + $crawler = self::request('GET', $cron_link . "&sid={$this->sid}", array(), false); + + $this->assert_forum_details($this->data['forums']['Prune Shadow'], array( + 'forum_posts_approved' => 0, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 0, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + ), 'after the cron job'); + } + + public function assert_forum_details($forum_id, $details, $additional_error_message = '') + { + $this->db = $this->get_db(); + + $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' + FROM phpbb_forums + WHERE forum_id = ' . (int) $forum_id; + $result = $this->db->sql_query($sql); + $data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); + } + + public function load_ids($data) + { + $this->db = $this->get_db(); + + if (!empty($data['forums'])) + { + $sql = 'SELECT * + FROM phpbb_forums + WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (in_array($row['forum_name'], $data['forums'])) + { + $this->data['forums'][$row['forum_name']] = (int) $row['forum_id']; + } + } + $this->db->sql_freeresult($result); + } + + if (!empty($data['topics'])) + { + $sql = 'SELECT * + FROM phpbb_topics + WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (in_array($row['topic_title'], $data['topics'])) + { + $this->data['topics'][$row['topic_title']] = (int) $row['topic_id']; + } + } + $this->db->sql_freeresult($result); + } + + if (!empty($data['posts'])) + { + $sql = 'SELECT * + FROM phpbb_posts + WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (in_array($row['post_subject'], $data['posts'])) + { + $this->data['posts'][$row['post_subject']] = (int) $row['post_id']; + } + } + $this->db->sql_freeresult($result); + } + } +} From d83d819827634931e9317469090e933edfc99f2b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 14 Mar 2014 23:35:07 +0100 Subject: [PATCH 07/11] [ticket/12150] Use shorter column names for prune settings All columns were renamed from having prune_shadow_topics as namebase to just prune_shadow. A missing column was also added to the migration file's remove_schema() method. PHPBB3-12150 --- phpBB/adm/style/acp_forums.html | 14 +++++++------- phpBB/includes/acp/acp_forums.php | 18 +++++++++--------- phpBB/language/en/acp/common.php | 2 +- phpBB/language/en/acp/forums.php | 4 ++-- .../cron/task/core/prune_shadow_topics.php | 12 ++++++------ .../data/v310/prune_shadow_topics.php | 15 ++++++++------- tests/functional/prune_shadow_topic_test.php | 6 +++--- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/phpBB/adm/style/acp_forums.html b/phpBB/adm/style/acp_forums.html index 2e826e7c13..0bb5e10f57 100644 --- a/phpBB/adm/style/acp_forums.html +++ b/phpBB/adm/style/acp_forums.html @@ -279,17 +279,17 @@
-

{L_FORUM_PRUNE_SHADOW_TOPICS_EXPLAIN}
-
-
+

{L_FORUM_PRUNE_SHADOW_EXPLAIN}
+
+
-

{L_AUTO_PRUNE_FREQ_EXPLAIN}
-
{L_DAYS}
+

{L_AUTO_PRUNE_FREQ_EXPLAIN}
+
{L_DAYS}
-

{L_AUTO_PRUNE_DAYS_EXPLAIN}
-
{L_DAYS}
+

{L_AUTO_PRUNE_DAYS_EXPLAIN}
+
{L_DAYS}
diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 4cce7b07ce..c47d9bc185 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -138,15 +138,15 @@ class acp_forums 'enable_prune' => request_var('enable_prune', false), 'enable_post_review' => request_var('enable_post_review', true), 'enable_quick_reply' => request_var('enable_quick_reply', false), - 'enable_shadow_topic_prune' => request_var('enable_shadow_topic_prune', false), + 'enable_shadow_prune' => request_var('enable_shadow_prune', false), 'prune_days' => request_var('prune_days', 7), 'prune_viewed' => request_var('prune_viewed', 7), 'prune_freq' => request_var('prune_freq', 1), 'prune_old_polls' => request_var('prune_old_polls', false), 'prune_announce' => request_var('prune_announce', false), 'prune_sticky' => request_var('prune_sticky', false), - 'prune_shadow_topic_days' => request_var('prune_shadow_topic_days', 7), - 'prune_shadow_topic_freq' => request_var('prune_shadow_topic_freq', 1), + 'prune_shadow_days' => request_var('prune_shadow_days', 7), + 'prune_shadow_freq' => request_var('prune_shadow_freq', 1), 'forum_password' => request_var('forum_password', '', true), 'forum_password_confirm'=> request_var('forum_password_confirm', '', true), 'forum_password_unset' => request_var('forum_password_unset', false), @@ -460,9 +460,9 @@ class acp_forums 'prune_days' => 7, 'prune_viewed' => 7, 'prune_freq' => 1, - 'enable_shadow_topic_prune' => false, - 'prune_shadow_topic_days' => 7, - 'prune_shadow_topic_freq' => 1, + 'enable_shadow_prune' => false, + 'prune_shadow_days' => 7, + 'prune_shadow_freq' => 1, 'forum_flags' => FORUM_FLAG_POST_REVIEW + FORUM_FLAG_ACTIVE_TOPICS, 'forum_options' => 0, 'forum_password' => '', @@ -642,8 +642,8 @@ class acp_forums 'PRUNE_FREQ' => $forum_data['prune_freq'], 'PRUNE_DAYS' => $forum_data['prune_days'], 'PRUNE_VIEWED' => $forum_data['prune_viewed'], - 'PRUNE_SHADOW_TOPIC_FREQ' => $forum_data['prune_shadow_topic_freq'], - 'PRUNE_SHADOW_TOPIC_DAYS' => $forum_data['prune_shadow_topic_days'], + 'PRUNE_SHADOW_FREQ' => $forum_data['prune_shadow_freq'], + 'PRUNE_SHADOW_DAYS' => $forum_data['prune_shadow_days'], 'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'], 'FORUM_RULES_LINK' => $forum_data['forum_rules_link'], 'FORUM_RULES' => $forum_data['forum_rules'], @@ -676,7 +676,7 @@ class acp_forums 'S_DISPLAY_SUBFORUM_LIST' => ($forum_data['display_subforum_list']) ? true : false, 'S_DISPLAY_ON_INDEX' => ($forum_data['display_on_index']) ? true : false, 'S_PRUNE_ENABLE' => ($forum_data['enable_prune']) ? true : false, - 'S_PRUNE_SHADOW_TOPIC_ENABLE' => ($forum_data['enable_shadow_topic_prune']) ? true : false, + 'S_PRUNE_SHADOW_ENABLE' => ($forum_data['enable_shadow_prune']) ? true : false, 'S_FORUM_LINK_TRACK' => ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false, 'S_PRUNE_OLD_POLLS' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false, 'S_PRUNE_ANNOUNCE' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false, diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 8c748fe463..2dc58d8361 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -676,7 +676,7 @@ $lang = array_merge($lang, array( 'LOG_PRUNE' => 'Pruned forums
» %s', 'LOG_AUTO_PRUNE' => 'Auto-pruned forums
» %s', - 'LOG_PRUNE_SHADOW_TOPIC' => 'Auto-pruned shadow topics
» %s', + 'LOG_PRUNE_SHADOW' => 'Auto-pruned shadow topics
» %s', 'LOG_PRUNE_USER_DEAC' => 'Users deactivated
» %s', 'LOG_PRUNE_USER_DEL_DEL' => 'Users pruned and posts deleted
» %s', 'LOG_PRUNE_USER_DEL_ANON' => 'Users pruned and posts retained
» %s', diff --git a/phpBB/language/en/acp/forums.php b/phpBB/language/en/acp/forums.php index f452dad8a0..d64380b6b6 100644 --- a/phpBB/language/en/acp/forums.php +++ b/phpBB/language/en/acp/forums.php @@ -101,8 +101,8 @@ $lang = array_merge($lang, array( 'FORUM_PASSWORD_OLD' => 'The forum password is using an old hashing method and should be changed.', 'FORUM_PASSWORD_MISMATCH' => 'The passwords you entered did not match.', 'FORUM_PRUNE_SETTINGS' => 'Forum prune settings', - 'FORUM_PRUNE_SHADOW_TOPICS' => 'Enable auto-pruning of shadow topics', - 'FORUM_PRUNE_SHADOW_TOPICS_EXPLAIN' => 'Prunes the forum of shadow topics, set the frequency/age parameters below.', + 'FORUM_PRUNE_SHADOW' => 'Enable auto-pruning of shadow topics', + 'FORUM_PRUNE_SHADOW_EXPLAIN' => 'Prunes the forum of shadow topics, set the frequency/age parameters below.', 'FORUM_RESYNCED' => 'Forum “%s” successfully resynced', 'FORUM_RULES_EXPLAIN' => 'Forum rules are displayed at any page within the given forum.', 'FORUM_RULES_LINK' => 'Link to forum rules', diff --git a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php index 4d7166ccb3..75165d900d 100644 --- a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php +++ b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php @@ -73,9 +73,9 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext); } - if ($this->forum_data['prune_shadow_topic_days']) + if ($this->forum_data['prune_shadow_days']) { - $this->auto_prune_shadow_topics($this->forum_data['forum_id'], 'shadow', $this->forum_data['forum_flags'], $this->forum_data['prune_shadow_topic_days'], $this->forum_data['prune_shadow_topic_freq']); + $this->auto_prune_shadow_topics($this->forum_data['forum_id'], 'shadow', $this->forum_data['forum_flags'], $this->forum_data['prune_shadow_days'], $this->forum_data['prune_shadow_freq']); } } @@ -105,7 +105,7 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t */ public function should_run() { - return $this->forum_data['enable_shadow_topic_prune'] && $this->forum_data['prune_shadow_topic_next'] < time(); + return $this->forum_data['enable_shadow_prune'] && $this->forum_data['prune_shadow_next'] < time(); } /** @@ -136,7 +136,7 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t { $forum_id = $request->variable('f', 0); - $sql = 'SELECT forum_id, prune_shadow_topic_next, enable_shadow_topic_prune, prune_shadow_topic_days, forum_flags, prune_shadow_topic_freq + $sql = 'SELECT forum_id, prune_shadow_next, enable_shadow_prune, prune_shadow_days, forum_flags, prune_shadow_freq FROM ' . FORUMS_TABLE . " WHERE forum_id = $forum_id"; $result = $this->db->sql_query($sql); @@ -176,11 +176,11 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t prune($forum_id, $prune_mode, $prune_date, $prune_flags, true); $sql = 'UPDATE ' . FORUMS_TABLE . " - SET prune_shadow_topic_next = $next_prune + SET prune_shadow_next = $next_prune WHERE forum_id = $forum_id"; $this->db->sql_query($sql); - add_log('admin', 'LOG_PRUNE_SHADOW_TOPIC', $row['forum_name']); + add_log('admin', 'LOG_PRUNE_SHADOW', $row['forum_name']); } return; diff --git a/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php b/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php index 0cf9981c14..1e7cfb5acb 100644 --- a/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php +++ b/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php @@ -21,10 +21,10 @@ class prune_shadow_topics extends \phpbb\db\migration\migration return array( 'add_columns' => array( $this->table_prefix . 'forums' => array( - 'enable_shadow_topic_prune' => array('BOOL', 0, 'after' => 'prune_freq'), - 'prune_shadow_topic_days' => array('UINT', 7, 'after' => 'enable_shadow_topic_prune'), - 'prune_shadow_topic_freq' => array('UINT', 1, 'after' => 'prune_shadow_topic_freq'), - 'prune_shadow_topic_next' => array('INT:11', 0, 'after' => 'prune_shadow_topic_freq'), + 'enable_shadow_prune' => array('BOOL', 0, 'after' => 'prune_freq'), + 'prune_shadow_days' => array('UINT', 7, 'after' => 'enable_shadow_prune'), + 'prune_shadow_freq' => array('UINT', 1, 'after' => 'prune_shadow_freq'), + 'prune_shadow_next' => array('INT:11', 0, 'after' => 'prune_shadow_freq'), ), ), ); @@ -35,9 +35,10 @@ class prune_shadow_topics extends \phpbb\db\migration\migration return array( 'drop_columns' => array( $this->table_prefix . 'forums' => array( - 'enable_shadow_topic_prune', - 'prune_shadow_topic_days', - 'prune_shadow_topic_freq', + 'enable_shadow_prune', + 'prune_shadow_days', + 'prune_shadow_freq', + 'prune_shadow_next', ), ), ); diff --git a/tests/functional/prune_shadow_topic_test.php b/tests/functional/prune_shadow_topic_test.php index 1db8c3aab7..901cedb389 100644 --- a/tests/functional/prune_shadow_topic_test.php +++ b/tests/functional/prune_shadow_topic_test.php @@ -27,9 +27,9 @@ class phpbb_functional_prune_shadow_topic_test extends phpbb_functional_test_cas $crawler = self::submit($form); $form = $crawler->selectButton('update')->form(array( 'forum_perm_from' => 2, - 'enable_shadow_topic_prune' => true, - 'prune_shadow_topic_freq' => 1, - 'prune_shadow_topic_days' => 1, + 'enable_shadow_prune' => true, + 'prune_shadow_freq' => 1, + 'prune_shadow_days' => 1, )); $crawler = self::submit($form); } From 494dd4110b04dc2543fdddd376d4baebac0ee0fe Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 29 Mar 2014 21:29:22 +0100 Subject: [PATCH 08/11] [ticket/12150] Use log service instead of add_log() function PHPBB3-12150 --- phpBB/config/cron_tasks.yml | 1 + phpBB/phpbb/cron/task/core/prune_shadow_topics.php | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/phpBB/config/cron_tasks.yml b/phpBB/config/cron_tasks.yml index 3fd049f567..4fa5d1440e 100644 --- a/phpBB/config/cron_tasks.yml +++ b/phpBB/config/cron_tasks.yml @@ -30,6 +30,7 @@ services: - %core.php_ext% - @config - @dbal.conn + - @log calls: - [set_name, [cron.task.core.prune_shadow_topics]] tags: diff --git a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php index 75165d900d..b30e665a87 100644 --- a/phpBB/phpbb/cron/task/core/prune_shadow_topics.php +++ b/phpBB/phpbb/cron/task/core/prune_shadow_topics.php @@ -24,6 +24,7 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t protected $php_ext; protected $config; protected $db; + protected $log; /** * If $forum_data is given, it is assumed to contain necessary information @@ -42,13 +43,15 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t * @param string $php_ext The PHP extension * @param \phpbb\config\config $config The config * @param \phpbb\db\driver\driver $db The db connection + * @param \phpbb\log\log $log The phpBB log system */ - public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, \phpbb\db\driver\driver $db) + public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, \phpbb\db\driver\driver $db, \phpbb\log\log $log) { $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; $this->config = $config; $this->db = $db; + $this->log = $log; } /** @@ -180,7 +183,7 @@ class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\t WHERE forum_id = $forum_id"; $this->db->sql_query($sql); - add_log('admin', 'LOG_PRUNE_SHADOW', $row['forum_name']); + $this->log->add('admin', 'LOG_PRUNE_SHADOW', $row['forum_name']); } return; From 1812d3ce99b88bbde130c2fff2c9363198baea5f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 30 Mar 2014 13:06:18 +0200 Subject: [PATCH 09/11] [ticket/12150] Update schema files for prune shadow topics PHPBB3-12150 --- phpBB/install/schemas/schema.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/phpBB/install/schemas/schema.json b/phpBB/install/schemas/schema.json index 15d2fd6e84..3d819e19b9 100644 --- a/phpBB/install/schemas/schema.json +++ b/phpBB/install/schemas/schema.json @@ -800,6 +800,26 @@ "UINT:20", 0 ], + "enable_shadow_prune": { + "0": "BOOL", + "1": 0, + "after": "prune_freq" + }, + "prune_shadow_days": { + "0": "UINT", + "1": 7, + "after": "enable_shadow_prune" + }, + "prune_shadow_freq": { + "0": "UINT", + "1": 1, + "after": "prune_shadow_freq" + }, + "prune_shadow_next": { + "0": "INT:11", + "1": 0, + "after": "prune_shadow_freq" + }, "forum_posts_approved": [ "UINT", 0 From 808c5277a9af39a64290948cc21cde7cd766b3b5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 3 Apr 2014 11:07:58 +0200 Subject: [PATCH 10/11] [ticket/12150] Remove 'after' for columns from migrations file PHPBB3-12150 --- phpBB/install/schemas/schema.json | 36 +++++++++---------- .../data/v310/prune_shadow_topics.php | 8 ++--- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/phpBB/install/schemas/schema.json b/phpBB/install/schemas/schema.json index 3d819e19b9..176691f1a6 100644 --- a/phpBB/install/schemas/schema.json +++ b/phpBB/install/schemas/schema.json @@ -800,26 +800,22 @@ "UINT:20", 0 ], - "enable_shadow_prune": { - "0": "BOOL", - "1": 0, - "after": "prune_freq" - }, - "prune_shadow_days": { - "0": "UINT", - "1": 7, - "after": "enable_shadow_prune" - }, - "prune_shadow_freq": { - "0": "UINT", - "1": 1, - "after": "prune_shadow_freq" - }, - "prune_shadow_next": { - "0": "INT:11", - "1": 0, - "after": "prune_shadow_freq" - }, + "enable_shadow_prune": [ + "BOOL", + 0 + ], + "prune_shadow_days": [ + "UINT", + 7 + ], + "prune_shadow_freq": [ + "UINT", + 1 + ], + "prune_shadow_next": [ + "INT:11", + 0 + ], "forum_posts_approved": [ "UINT", 0 diff --git a/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php b/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php index 1e7cfb5acb..d625b1fe6e 100644 --- a/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php +++ b/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php @@ -21,10 +21,10 @@ class prune_shadow_topics extends \phpbb\db\migration\migration return array( 'add_columns' => array( $this->table_prefix . 'forums' => array( - 'enable_shadow_prune' => array('BOOL', 0, 'after' => 'prune_freq'), - 'prune_shadow_days' => array('UINT', 7, 'after' => 'enable_shadow_prune'), - 'prune_shadow_freq' => array('UINT', 1, 'after' => 'prune_shadow_freq'), - 'prune_shadow_next' => array('INT:11', 0, 'after' => 'prune_shadow_freq'), + 'enable_shadow_prune' => array('BOOL', 0), + 'prune_shadow_days' => array('UINT', 7), + 'prune_shadow_freq' => array('UINT', 1), + 'prune_shadow_next' => array('INT:11', 0), ), ), ); From e83c6cb61dcac9c8460e0e8fd22cb2f3324fb248 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 5 Apr 2014 11:14:41 +0200 Subject: [PATCH 11/11] [ticket/12150] Use correct license URL in prune shadow migrations file PHPBB3-12150 --- phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php b/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php index d625b1fe6e..83f5f903e8 100644 --- a/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php +++ b/phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php @@ -3,7 +3,7 @@ * * @package migration * @copyright (c) 2014 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */