aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2014-01-31 23:06:03 +0100
committerMarc Alexander <admin@m-a-styles.de>2014-03-29 21:56:53 +0100
commit02fdae4e8800ded878dcdc848563aef202069317 (patch)
tree41e28f919b8ac913c94a3c895edf4f7364ee3dfb /phpBB
parenta7abf8218dd8440926549df1f5659820f05fd76a (diff)
downloadforums-02fdae4e8800ded878dcdc848563aef202069317.tar
forums-02fdae4e8800ded878dcdc848563aef202069317.tar.gz
forums-02fdae4e8800ded878dcdc848563aef202069317.tar.bz2
forums-02fdae4e8800ded878dcdc848563aef202069317.tar.xz
forums-02fdae4e8800ded878dcdc848563aef202069317.zip
[ticket/12150] Add file and caller for pruning shadow topics
PHPBB3-12150
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/config/cron_tasks.yml12
-rw-r--r--phpBB/includes/functions_admin.php5
-rw-r--r--phpBB/language/en/acp/common.php1
-rw-r--r--phpBB/phpbb/cron/task/core/prune_shadow_topics.php188
-rw-r--r--phpBB/viewforum.php12
5 files changed, 218 insertions, 0 deletions
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' => '<strong>Pruned forums</strong><br />» %s',
'LOG_AUTO_PRUNE' => '<strong>Auto-pruned forums</strong><br />» %s',
+ 'LOG_PRUNE_SHADOW_TOPIC' => '<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',
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 @@
+<?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;
+
+ /**
+ * 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
+ */
+ public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, \phpbb\db\driver\driver $db)
+ {
+ $this->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', '<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