Skip to content

Loading…

[ticket/12150] Automatically prune shadow topics #1987

Closed
wants to merge 8 commits into from

2 participants

@marc1706
phpBB Forum Software member

Automatically prune shadow topics per forum after a given timeframe using a cronjob. Admins will be able to define a given timeframe in days after which shadow topics should be deleted and a frequency for pruning them.

Ticket: http://tracker.phpbb.com/browse/PHPBB3-12150

@nickvergessen
phpBB Forum Software member

I think it would be nice to hide the options when pruning is disabled...

@nickvergessen nickvergessen reopened this
@marc1706
phpBB Forum Software member

Wouldn't this require one to use javascript for that or what do you exactly mean with hiding the options?

@nickvergessen
phpBB Forum Software member

@marc1706 yes, I think if JS is enabled we can make the interface easier and cleaner for the user by hiding options that have no result

@marc1706 marc1706 [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
94cbae6
@nickvergessen nickvergessen commented on the diff
tests/functional/prune_shadow_topic_test.php
((105 lines not shown))
+ $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();
@nickvergessen phpBB Forum Software member

Not required for functional tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@nickvergessen nickvergessen commented on an outdated diff
phpBB/phpbb/cron/task/core/prune_shadow_topics.php
((168 lines not shown))
+ $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_next = $next_prune
+ WHERE forum_id = $forum_id";
+ $this->db->sql_query($sql);
+
+ add_log('admin', 'LOG_PRUNE_SHADOW', $row['forum_name']);
@nickvergessen phpBB Forum Software member

use \phpbb\log\log->add() in new code please (and add dependency)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@marc1706
phpBB Forum Software member

Rebasing onto develop-ascraeus

@marc1706 marc1706 closed this
@marc1706
phpBB Forum Software member

New PR #2212

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 2, 2014
  1. @marc1706

    [ticket/12150] Add options to acp

    marc1706 committed
    PHPBB3-12150
  2. @marc1706
  3. @marc1706
  4. @marc1706
  5. @marc1706
  6. @marc1706
Commits on Mar 14, 2014
  1. @marc1706

    [ticket/12150] Use shorter column names for prune settings

    marc1706 committed
    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
Commits on Mar 29, 2014
  1. @marc1706
View
13 phpBB/adm/style/acp_forums.html
@@ -278,6 +278,19 @@
<dd><label><input type="radio" class="radio" name="prune_sticky" value="1"<!-- IF S_PRUNE_STICKY --> id="prune_sticky" checked="checked"<!-- ENDIF --> /> {L_YES}</label>
<label><input type="radio" class="radio" name="prune_sticky" value="0"<!-- IF not S_PRUNE_STICKY --> id="prune_sticky" checked="checked"<!-- ENDIF --> /> {L_NO}</label></dd>
</dl>
+ <dl>
+ <dt><label for="enable_shadow_prune">{L_FORUM_PRUNE_SHADOW}{L_COLON}</label><br /><span>{L_FORUM_PRUNE_SHADOW_EXPLAIN}</span></dt>
+ <dd><label><input type="radio" class="radio" name="enable_shadow_prune" value="1"<!-- IF S_PRUNE_SHADOW_ENABLE --> id="enable_shadow_prune" checked="checked"<!-- ENDIF --> /> {L_YES}</label>
+ <label><input type="radio" class="radio" name="enable_shadow_prune" value="0"<!-- IF not S_PRUNE_SHADOW_ENABLE --> id="enable_shadow_prune" checked="checked"<!-- ENDIF --> /> {L_NO}</label></dd>
+ </dl>
+ <dl>
+ <dt><label for="prune_shadow_freq">{L_AUTO_PRUNE_FREQ}{L_COLON}</label><br /><span>{L_AUTO_PRUNE_FREQ_EXPLAIN}</span></dt>
+ <dd><input type="number" id="prune_shadow_freq" name="prune_shadow_freq" value="{PRUNE_FREQ}" maxlength="4" size="4" min="0" max="9999" /> {L_DAYS}</dd>
+ </dl>
+ <dl>
+ <dt><label for="prune_shadow_days">{L_AUTO_PRUNE_DAYS}{L_COLON}</label><br /><span>{L_AUTO_PRUNE_DAYS_EXPLAIN}</span></dt>
+ <dd><input type="number" id="prune_shadow_days" name="prune_shadow_days" value="{PRUNE_DAYS}" maxlength="4" size="4" min="0" max="9999" /> {L_DAYS}</dd>
+ </dl>
</fieldset>
</div>
View
13 phpBB/config/cron_tasks.yml
@@ -23,6 +23,19 @@ 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
+ - @log
+ 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:
View
9 phpBB/includes/acp/acp_forums.php
@@ -138,12 +138,15 @@ function main($id, $mode)
'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_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_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),
@@ -457,6 +460,9 @@ function main($id, $mode)
'prune_days' => 7,
'prune_viewed' => 7,
'prune_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' => '',
@@ -636,6 +642,8 @@ function main($id, $mode)
'PRUNE_FREQ' => $forum_data['prune_freq'],
'PRUNE_DAYS' => $forum_data['prune_days'],
'PRUNE_VIEWED' => $forum_data['prune_viewed'],
+ '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'],
@@ -668,6 +676,7 @@ function main($id, $mode)
'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_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,
View
4 phpBB/includes/db/schema_data.php
@@ -352,6 +352,10 @@
'prune_days' => array('UINT', 0),
'prune_viewed' => array('UINT', 0),
'prune_freq' => array('UINT', 0),
+ 'enable_shadow_prune' => array('BOOL', 0),
+ 'prune_shadow_next' => array('TIMESTAMP', 0),
+ 'prune_shadow_days' => array('UINT', 0),
+ 'prune_shadow_freq' => array('UINT', 0),
),
'PRIMARY_KEY' => 'forum_id',
'KEYS' => array(
View
5 phpBB/includes/functions_admin.php
@@ -2275,6 +2275,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_status = ' . 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) . "
View
6 phpBB/install/schemas/firebird_schema.sql
@@ -394,7 +394,11 @@ CREATE TABLE phpbb_forums (
prune_next INTEGER DEFAULT 0 NOT NULL,
prune_days INTEGER DEFAULT 0 NOT NULL,
prune_viewed INTEGER DEFAULT 0 NOT NULL,
- prune_freq INTEGER DEFAULT 0 NOT NULL
+ prune_freq INTEGER DEFAULT 0 NOT NULL,
+ enable_shadow_prune INTEGER DEFAULT 0 NOT NULL,
+ prune_shadow_next INTEGER DEFAULT 0 NOT NULL,
+ prune_shadow_days INTEGER DEFAULT 0 NOT NULL,
+ prune_shadow_freq INTEGER DEFAULT 0 NOT NULL
);;
ALTER TABLE phpbb_forums ADD PRIMARY KEY (forum_id);;
View
6 phpBB/install/schemas/mssql_schema.sql
@@ -481,7 +481,11 @@ CREATE TABLE [phpbb_forums] (
[prune_next] [int] DEFAULT (0) NOT NULL ,
[prune_days] [int] DEFAULT (0) NOT NULL ,
[prune_viewed] [int] DEFAULT (0) NOT NULL ,
- [prune_freq] [int] DEFAULT (0) NOT NULL
+ [prune_freq] [int] DEFAULT (0) NOT NULL ,
+ [enable_shadow_prune] [int] DEFAULT (0) NOT NULL ,
+ [prune_shadow_next] [int] DEFAULT (0) NOT NULL ,
+ [prune_shadow_days] [int] DEFAULT (0) NOT NULL ,
+ [prune_shadow_freq] [int] DEFAULT (0) NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
View
4 phpBB/install/schemas/mysql_40_schema.sql
@@ -280,6 +280,10 @@ CREATE TABLE phpbb_forums (
prune_days mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
prune_viewed mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
prune_freq mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
+ enable_shadow_prune tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
+ prune_shadow_next int(11) UNSIGNED DEFAULT '0' NOT NULL,
+ prune_shadow_days mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
+ prune_shadow_freq mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
PRIMARY KEY (forum_id),
KEY left_right_id (left_id, right_id),
KEY forum_lastpost_id (forum_last_post_id)
View
4 phpBB/install/schemas/mysql_41_schema.sql
@@ -280,6 +280,10 @@ CREATE TABLE phpbb_forums (
prune_days mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
prune_viewed mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
prune_freq mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
+ enable_shadow_prune tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
+ prune_shadow_next int(11) UNSIGNED DEFAULT '0' NOT NULL,
+ prune_shadow_days mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
+ prune_shadow_freq mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
PRIMARY KEY (forum_id),
KEY left_right_id (left_id, right_id),
KEY forum_lastpost_id (forum_last_post_id)
View
4 phpBB/install/schemas/oracle_schema.sql
@@ -543,6 +543,10 @@ CREATE TABLE phpbb_forums (
prune_days number(8) DEFAULT '0' NOT NULL,
prune_viewed number(8) DEFAULT '0' NOT NULL,
prune_freq number(8) DEFAULT '0' NOT NULL,
+ enable_shadow_prune number(1) DEFAULT '0' NOT NULL,
+ prune_shadow_next number(11) DEFAULT '0' NOT NULL,
+ prune_shadow_days number(8) DEFAULT '0' NOT NULL,
+ prune_shadow_freq number(8) DEFAULT '0' NOT NULL,
CONSTRAINT pk_phpbb_forums PRIMARY KEY (forum_id)
)
/
View
4 phpBB/install/schemas/postgres_schema.sql
@@ -418,6 +418,10 @@ CREATE TABLE phpbb_forums (
prune_days INT4 DEFAULT '0' NOT NULL CHECK (prune_days >= 0),
prune_viewed INT4 DEFAULT '0' NOT NULL CHECK (prune_viewed >= 0),
prune_freq INT4 DEFAULT '0' NOT NULL CHECK (prune_freq >= 0),
+ enable_shadow_prune INT2 DEFAULT '0' NOT NULL CHECK (enable_shadow_prune >= 0),
+ prune_shadow_next INT4 DEFAULT '0' NOT NULL CHECK (prune_shadow_next >= 0),
+ prune_shadow_days INT4 DEFAULT '0' NOT NULL CHECK (prune_shadow_days >= 0),
+ prune_shadow_freq INT4 DEFAULT '0' NOT NULL CHECK (prune_shadow_freq >= 0),
PRIMARY KEY (forum_id)
);
View
6 phpBB/install/schemas/sqlite_schema.sql
@@ -272,7 +272,11 @@ CREATE TABLE phpbb_forums (
prune_next INTEGER UNSIGNED NOT NULL DEFAULT '0',
prune_days INTEGER UNSIGNED NOT NULL DEFAULT '0',
prune_viewed INTEGER UNSIGNED NOT NULL DEFAULT '0',
- prune_freq INTEGER UNSIGNED NOT NULL DEFAULT '0'
+ prune_freq INTEGER UNSIGNED NOT NULL DEFAULT '0',
+ enable_shadow_prune INTEGER UNSIGNED NOT NULL DEFAULT '0',
+ prune_shadow_next INTEGER UNSIGNED NOT NULL DEFAULT '0',
+ prune_shadow_days INTEGER UNSIGNED NOT NULL DEFAULT '0',
+ prune_shadow_freq INTEGER UNSIGNED NOT NULL DEFAULT '0'
);
CREATE INDEX phpbb_forums_left_right_id ON phpbb_forums (left_id, right_id);
View
1 phpBB/language/en/acp/common.php
@@ -677,6 +677,7 @@
'LOG_PRUNE' => '<strong>Pruned forums</strong><br />» %s',
'LOG_AUTO_PRUNE' => '<strong>Auto-pruned forums</strong><br />» %s',
+ 'LOG_PRUNE_SHADOW' => '<strong>Auto-pruned shadow topics</strong><br />» %s',
'LOG_PRUNE_USER_DEAC' => '<strong>Users deactivated</strong><br />» %s',
'LOG_PRUNE_USER_DEL_DEL' => '<strong>Users pruned and posts deleted</strong><br />» %s',
'LOG_PRUNE_USER_DEL_ANON' => '<strong>Users pruned and posts retained</strong><br />» %s',
View
2 phpBB/language/en/acp/forums.php
@@ -101,6 +101,8 @@
'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' => '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',
View
191 phpBB/phpbb/cron/task/core/prune_shadow_topics.php
@@ -0,0 +1,191 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+namespace phpbb\cron\task\core;
+
+/**
+* Prune one forum of its shadow topics cron task.
+*
+* It is intended to be used when cron is invoked via web.
+* This task can decide whether it should be run using data obtained by viewforum
+* code, without making additional database queries.
+*
+* @package phpBB3
+*/
+class prune_shadow_topics extends \phpbb\cron\task\base implements \phpbb\cron\task\parametrized
+{
+ protected $phpbb_root_path;
+ protected $php_ext;
+ protected $config;
+ protected $db;
+ protected $log;
+
+ /**
+ * If $forum_data is given, it is assumed to contain necessary information
+ * about a single forum that is to be pruned.
+ *
+ * If $forum_data is not given, forum id will be retrieved via request_var
+ * and a database query will be performed to load the necessary information
+ * about the forum.
+ */
+ protected $forum_data;
+
+ /**
+ * Constructor.
+ *
+ * @param string $phpbb_root_path The root path
+ * @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, \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;
+ }
+
+ /**
+ * 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_days'])
+ {
+ $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']);
+ }
+ }
+
+ /**
+ * 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_prune'] && $this->forum_data['prune_shadow_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_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);
+ $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_next = $next_prune
+ WHERE forum_id = $forum_id";
+ $this->db->sql_query($sql);
+
+ $this->log->add('admin', 'LOG_PRUNE_SHADOW', $row['forum_name']);
+ }
+
+ return;
+ }
+}
View
46 phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php
@@ -0,0 +1,46 @@
+<?php
+/**
+*
+* @package migration
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
+*
+*/
+
+namespace phpbb\db\migration\data\v310;
+
+class prune_shadow_topics extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array('\phpbb\db\migration\data\v310\dev');
+ }
+
+ public function update_schema()
+ {
+ 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'),
+ ),
+ ),
+ );
+ }
+
+ public function revert_schema()
+ {
+ return array(
+ 'drop_columns' => array(
+ $this->table_prefix . 'forums' => array(
+ 'enable_shadow_prune',
+ 'prune_shadow_days',
+ 'prune_shadow_freq',
+ 'prune_shadow_next',
+ ),
+ ),
+ );
+ }
+}
View
12 phpBB/viewforum.php
@@ -224,6 +224,18 @@
$url = $task->get_url();
$template->assign_var('RUN_CRON_TASK', '<img src="' . $url . '" width="1" height="1" alt="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', '<img src="' . $url . '" width="1" height="1" alt="cron" />');
+ }
+ }
}
// Forum rules and subscription info
View
207 tests/functional/prune_shadow_topic_test.php
@@ -0,0 +1,207 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_prune_shadow_topic_test extends phpbb_functional_test_case
+{
+ protected $data = array();
+ protected $post;
+
+ public function test_setup_forums()
+ {
+ $this->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_prune' => true,
+ 'prune_shadow_freq' => 1,
+ 'prune_shadow_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();
@nickvergessen phpBB Forum Software member

Not required for functional tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ // 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);
+ }
+ }
+}
Something went wrong with that request. Please try again.