diff --git a/phpBB/includes/cron_tasks/standard/prune_all_forums.php b/phpBB/includes/cron_tasks/standard/prune_all_forums.php index f54f5d9ed9..569752dcb0 100644 --- a/phpBB/includes/cron_tasks/standard/prune_all_forums.php +++ b/phpBB/includes/cron_tasks/standard/prune_all_forums.php @@ -32,6 +32,24 @@ class prune_all_forums_cron_task extends cron_task_base */ public function run() { + global $db; + $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq + FROM ' . FORUMS_TABLE . " + WHERE enable_prune = 1 and prune_next < " . time(); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if ($row['prune_days']) + { + auto_prune($row['forum_id'], 'posted', $row['forum_flags'], $row['prune_days'], $row['prune_freq']); + } + + if ($row['prune_viewed']) + { + auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']); + } + } + $db->sql_freeresult($result); } /** diff --git a/phpBB/includes/cron_tasks/standard/prune_forum.php b/phpBB/includes/cron_tasks/standard/prune_forum.php index 5ae1083677..f4ef2ea6dd 100644 --- a/phpBB/includes/cron_tasks/standard/prune_forum.php +++ b/phpBB/includes/cron_tasks/standard/prune_forum.php @@ -27,9 +27,42 @@ if (!defined('IN_PHPBB')) */ class prune_forum_cron_task extends cron_task_base implements parametrized_cron_task { - public function __construct($forum_data) + /** + * Constructor. + * + * 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. + */ + public function __construct($forum_data=null) { - $this->forum_data = $forum_data; + global $db; + if ($forum_data) + { + $this->forum_data = $forum_data; + } + else + { + $forum_id = request_var('f', 0); + + $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq + FROM ' . FORUMS_TABLE . " + WHERE forum_id = $forum_id"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$row) + { + // FIXME what to do? + break; + } + + $this->forum_data = $row; + } } /** @@ -37,6 +70,18 @@ class prune_forum_cron_task extends cron_task_base implements parametrized_cron_ */ public function run() { + global $phpbb_root_path, $phpEx; + include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + + if ($this->forum_data['prune_days']) + { + auto_prune($this->forum_data['forum_id'], 'posted', $this->forum_data['forum_flags'], $this->forum_data['prune_days'], $this->forum_data['prune_freq']); + } + + if ($this->forum_data['prune_viewed']) + { + auto_prune($this->forum_data['forum_id'], 'viewed', $this->forum_data['forum_flags'], $this->forum_data['prune_viewed'], $this->forum_data['prune_freq']); + } } /**