[feature/system-cron] Added implementations for run methods in prune cron tasks.

PHPBB3-9596
This commit is contained in:
Oleg Pudeyev 2010-04-15 10:05:47 -04:00
parent 0532048292
commit 3956e9f533
2 changed files with 65 additions and 2 deletions

View file

@ -32,6 +32,24 @@ class prune_all_forums_cron_task extends cron_task_base
*/ */
public function run() 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);
} }
/** /**

View file

@ -27,9 +27,42 @@ if (!defined('IN_PHPBB'))
*/ */
class prune_forum_cron_task extends cron_task_base implements parametrized_cron_task 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() 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']);
}
} }
/** /**