From 3c7ff1c417bd57ab71057fa3d880d58f1ee65f2a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 30 Jan 2014 22:21:06 +0100 Subject: [ticket/12150] Add options to acp PHPBB3-12150 --- .../db/migration/data/v310/prune_shadow_topics.php | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php (limited to 'phpBB/phpbb') 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', + ), + ), + ); + } +} -- cgit v1.2.1 From a7abf8218dd8440926549df1f5659820f05fd76a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 31 Jan 2014 22:37:27 +0100 Subject: [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(+) (limited to 'phpBB/phpbb') 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'), ), ), ); -- cgit v1.2.1 From 02fdae4e8800ded878dcdc848563aef202069317 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 31 Jan 2014 23:06:03 +0100 Subject: [ticket/12150] Add file and caller for pruning shadow topics PHPBB3-12150 --- phpBB/phpbb/cron/task/core/prune_shadow_topics.php | 188 +++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 phpBB/phpbb/cron/task/core/prune_shadow_topics.php (limited to 'phpBB/phpbb') 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; + } +} -- cgit v1.2.1 From d97c58aeeaf24b6d76e21642e1764b471f212d87 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 2 Feb 2014 12:52:57 +0100 Subject: [ticket/12150] Add missing prune settings variables in acp_forums PHPBB3-12150 --- phpBB/phpbb/cron/task/core/prune_shadow_topics.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb') 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']); } } -- cgit v1.2.1 From d83d819827634931e9317469090e933edfc99f2b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 14 Mar 2014 23:35:07 +0100 Subject: [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/phpbb/cron/task/core/prune_shadow_topics.php | 12 ++++++------ .../phpbb/db/migration/data/v310/prune_shadow_topics.php | 15 ++++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'phpBB/phpbb') 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', ), ), ); -- cgit v1.2.1 From 494dd4110b04dc2543fdddd376d4baebac0ee0fe Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 29 Mar 2014 21:29:22 +0100 Subject: [ticket/12150] Use log service instead of add_log() function PHPBB3-12150 --- phpBB/phpbb/cron/task/core/prune_shadow_topics.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb') 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; -- cgit v1.2.1 From 808c5277a9af39a64290948cc21cde7cd766b3b5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 3 Apr 2014 11:07:58 +0200 Subject: [ticket/12150] Remove 'after' for columns from migrations file PHPBB3-12150 --- phpBB/phpbb/db/migration/data/v310/prune_shadow_topics.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb') 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), ), ), ); -- cgit v1.2.1 From e83c6cb61dcac9c8460e0e8fd22cb2f3324fb248 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 5 Apr 2014 11:14:41 +0200 Subject: [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(-) (limited to 'phpBB/phpbb') 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 * */ -- cgit v1.2.1