PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,72 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task;
/**
* Cron task base class. Provides sensible defaults for cron tasks
* and partially implements cron task interface, making writing cron tasks easier.
*
* At a minimum, subclasses must override the run() method.
*
* Cron tasks need not inherit from this base class. If desired,
* they may implement cron task interface directly.
*/
abstract class base implements \phpbb\cron\task\task
{
private $name;
/**
* Returns the name of the task.
*
* @return string Name of wrapped task.
*/
public function get_name()
{
return $this->name;
}
/**
* Sets the name of the task.
*
* @param string $name The task name
*/
public function set_name($name)
{
$this->name = $name;
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* For example, a cron task that prunes forums can only run when
* forum pruning is enabled.
*
* @return bool
*/
public function is_runnable()
{
return true;
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* @return bool
*/
public function should_run()
{
return true;
}
}

View File

@ -0,0 +1,94 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task\core;
/**
* Prune all forums cron task.
*
* It is intended to be invoked from system cron.
* This task will find all forums for which pruning is enabled, and will
* prune all forums as necessary.
*/
class prune_all_forums extends \phpbb\cron\task\base
{
protected $phpbb_root_path;
protected $php_ext;
protected $config;
protected $db;
/**
* Constructor.
*
* @param string $phpbb_root_path The root path
* @param string $php_ext The PHP file extension
* @param \phpbb\config\config $config The config
* @param \phpbb\db\driver\driver_interface $db The db connection
*/
public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->config = $config;
$this->db = $db;
}
/**
* 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);
}
$sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, enable_shadow_prune, prune_shadow_days, prune_shadow_freq, prune_shadow_next, forum_flags, prune_freq
FROM ' . FORUMS_TABLE;
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
if ($row['enable_prune'] && $row['prune_next'] < time())
{
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']);
}
}
if ($row['enable_shadow_prune'] && $row['prune_shadow_next'] < time() && $row['prune_shadow_days'])
{
auto_prune($row['forum_id'], 'shadow', $row['forum_flags'], $row['prune_shadow_days'], $row['prune_shadow_freq']);
}
}
$this->db->sql_freeresult($result);
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* This cron task will only run when system cron is utilised.
*
* @return bool
*/
public function is_runnable()
{
return (bool) $this->config['use_system_cron'];
}
}

View File

@ -0,0 +1,159 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task\core;
/**
* Prune one forum 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.
*/
class prune_forum 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->variable()
* 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 PHP file extension
* @param \phpbb\config\config $config The config
* @param \phpbb\db\driver\driver_interface $db The db connection
*/
public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $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_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']);
}
}
/**
* 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_prune'] && $this->forum_data['prune_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_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_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;
}
}
}
}

View File

@ -0,0 +1,61 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task\core;
/**
* Prune notifications cron task.
*/
class prune_notifications extends \phpbb\cron\task\base
{
protected $config;
protected $notification_manager;
/**
* Constructor.
*
* @param \phpbb\config\config $config The config
* @param \phpbb\notification\manager $notification_manager Notification manager
*/
public function __construct(\phpbb\config\config $config, \phpbb\notification\manager $notification_manager)
{
$this->config = $config;
$this->notification_manager = $notification_manager;
}
/**
* {@inheritdoc}
*/
public function run()
{
// time minus expire days in seconds
$timestamp = time() - ($this->config['read_notification_expire_days'] * 60 * 60 * 24);
$this->notification_manager->prune_notifications($timestamp);
}
/**
* {@inheritdoc}
*/
public function is_runnable()
{
return (bool) $this->config['read_notification_expire_days'];
}
/**
* {@inheritdoc}
*/
public function should_run()
{
return $this->config['read_notification_last_gc'] < time() - $this->config['read_notification_gc'];
}
}

View File

@ -0,0 +1,200 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
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.
*/
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;
protected $user;
/**
* 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->variable()
* 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 PHP file extension
* @param \phpbb\config\config $config The config
* @param \phpbb\db\driver\driver_interface $db The db connection
* @param \phpbb\log\log $log The phpBB log system
* @param \phpbb\user $user The phpBB user object
*/
public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\log\log $log, \phpbb\user $user)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->config = $config;
$this->db = $db;
$this->log = $log;
$this->user = $user;
}
/**
* 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_days Prune date in days
* @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);
$user_id = (empty($this->user->data)) ? ANONYMOUS : $this->user->data['user_id'];
$user_ip = (empty($this->user->ip)) ? '' : $this->user->ip;
$this->log->add('admin', $user_id, $user_ip, 'LOG_PRUNE_SHADOW', false, array($row['forum_name']));
}
return;
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task\core;
/**
* Queue cron task. Sends email and jabber messages queued by other scripts.
*/
class queue extends \phpbb\cron\task\base
{
protected $phpbb_root_path;
protected $php_ext;
protected $cache_dir;
protected $config;
/**
* Constructor.
*
* @param string $phpbb_root_path The root path
* @param string $php_ext PHP file extension
* @param \phpbb\config\config $config The config
* @param string $cache_dir phpBB cache directory
*/
public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, $cache_dir)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->config = $config;
$this->cache_dir = $cache_dir;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
if (!class_exists('queue'))
{
include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext);
}
$queue = new \queue();
$queue->process();
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* Queue task is only run if the email queue (file) exists.
*
* @return bool
*/
public function is_runnable()
{
return file_exists($this->cache_dir . 'queue.' . $this->php_ext);
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* The interval between queue runs is specified in board configuration.
*
* @return bool
*/
public function should_run()
{
return $this->config['last_queue_run'] < time() - $this->config['queue_interval'];
}
}

View File

@ -0,0 +1,72 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task\core;
/**
* Tidy cache cron task.
*/
class tidy_cache extends \phpbb\cron\task\base
{
protected $config;
protected $cache;
/**
* Constructor.
*
* @param \phpbb\config\config $config The config
* @param \phpbb\cache\driver\driver_interface $cache The cache driver
*/
public function __construct(\phpbb\config\config $config, \phpbb\cache\driver\driver_interface $cache)
{
$this->config = $config;
$this->cache = $cache;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
$this->cache->tidy();
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* Tidy cache cron task runs if the cache implementation in use
* supports tidying.
*
* @return bool
*/
public function is_runnable()
{
return true;
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* The interval between cache tidying is specified in board
* configuration.
*
* @return bool
*/
public function should_run()
{
return $this->config['cache_last_gc'] < time() - $this->config['cache_gc'];
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task\core;
/**
* Tidy database cron task.
*/
class tidy_database extends \phpbb\cron\task\base
{
protected $phpbb_root_path;
protected $php_ext;
protected $config;
/**
* Constructor.
*
* @param string $phpbb_root_path The root path
* @param string $php_ext The PHP file extension
* @param \phpbb\config\config $config The config
*/
public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->config = $config;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
if (!function_exists('tidy_database'))
{
include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);
}
tidy_database();
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* The interval between database tidying is specified in board
* configuration.
*
* @return bool
*/
public function should_run()
{
return $this->config['database_last_gc'] < time() - $this->config['database_gc'];
}
}

View File

@ -0,0 +1,126 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task\core;
/**
* Cron task for cleaning plupload's temporary upload directory.
*/
class tidy_plupload extends \phpbb\cron\task\base
{
/**
* How old a file must be (in seconds) before it is deleted.
* @var int
*/
protected $max_file_age = 86400;
/**
* How often we run the cron (in seconds).
* @var int
*/
protected $cron_frequency = 86400;
/**
* phpBB root path
* @var string
*/
protected $phpbb_root_path;
/**
* Config object
* @var \phpbb\config\config
*/
protected $config;
/** @var \phpbb\log\log_interface */
protected $log;
/** @var \phpbb\user */
protected $user;
/**
* Directory where plupload stores temporary files.
* @var string
*/
protected $plupload_upload_path;
/**
* Constructor.
*
* @param string $phpbb_root_path The root path
* @param \phpbb\config\config $config The config
* @param \phpbb\log\log_interface $log Log
* @param \phpbb\user $user User object
*/
public function __construct($phpbb_root_path, \phpbb\config\config $config, \phpbb\log\log_interface $log, \phpbb\user $user)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->config = $config;
$this->log = $log;
$this->user = $user;
$this->plupload_upload_path = $this->phpbb_root_path . $this->config['upload_path'] . '/plupload';
}
/**
* {@inheritDoc}
*/
public function run()
{
// Remove old temporary file (perhaps failed uploads?)
$last_valid_timestamp = time() - $this->max_file_age;
try
{
$iterator = new \DirectoryIterator($this->plupload_upload_path);
foreach ($iterator as $file)
{
if (strpos($file->getBasename(), $this->config['plupload_salt']) !== 0)
{
// Skip over any non-plupload files.
continue;
}
if ($file->getMTime() < $last_valid_timestamp)
{
@unlink($file->getPathname());
}
}
}
catch (\UnexpectedValueException $e)
{
$this->log->add('critical', $this->user->data['user_id'], $this->user->ip, 'LOG_PLUPLOAD_TIDY_FAILED', false, array(
$this->plupload_upload_path,
$e->getMessage(),
$e->getTraceAsString()
));
}
$this->config->set('plupload_last_gc', time(), true);
}
/**
* {@inheritDoc}
*/
public function is_runnable()
{
return !empty($this->config['plupload_salt']) && is_dir($this->plupload_upload_path);
}
/**
* {@inheritDoc}
*/
public function should_run()
{
return $this->config['plupload_last_gc'] < time() - $this->cron_frequency;
}
}

View File

@ -0,0 +1,133 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task\core;
/**
* Tidy search cron task.
*
* Will only run when the currently selected search backend supports tidying.
*/
class tidy_search extends \phpbb\cron\task\base
{
/**
* phpBB root path
* @var string
*/
protected $phpbb_root_path;
/**
* PHP file extension
* @var string
*/
protected $php_ext;
/**
* Auth object
* @var \phpbb\auth\auth
*/
protected $auth;
/**
* Config object
* @var \phpbb\config\config
*/
protected $config;
/**
* Database object
* @var \phpbb\db\driver\driver_interface
*/
protected $db;
/**
* User object
* @var \phpbb\user
*/
protected $user;
/**
* Event dispatcher object
* @var \phpbb\event\dispatcher_interface
*/
protected $phpbb_dispatcher;
/**
* Constructor.
*
* @param string $phpbb_root_path The phpBB root path
* @param string $php_ext The PHP file extension
* @param \phpbb\auth\auth $auth The auth object
* @param \phpbb\config\config $config The config object
* @param \phpbb\db\driver\driver_interface $db The database object
* @param \phpbb\user $user The user object
* @param \phpbb\event\dispatcher_interface $phpbb_dispatcher The event dispatcher object
*/
public function __construct($phpbb_root_path, $php_ext, \phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\event\dispatcher_interface $phpbb_dispatcher)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->auth = $auth;
$this->config = $config;
$this->db = $db;
$this->user = $user;
$this->phpbb_dispatcher = $phpbb_dispatcher;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
$search_type = $this->config['search_type'];
// We do some additional checks in the module to ensure it can actually be utilised
$error = false;
$search = new $search_type($error, $this->phpbb_root_path, $this->php_ext, $this->auth, $this->config, $this->db, $this->user, $this->phpbb_dispatcher);
if (!$error)
{
$search->tidy();
}
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* Search cron task is runnable in all normal use. It may not be
* runnable if the search backend implementation selected in board
* configuration does not exist.
*
* @return bool
*/
public function is_runnable()
{
return class_exists($this->config['search_type']);
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* The interval between search tidying is specified in board
* configuration.
*
* @return bool
*/
public function should_run()
{
return $this->config['search_last_gc'] < time() - $this->config['search_gc'];
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task\core;
/**
* Tidy sessions cron task.
*/
class tidy_sessions extends \phpbb\cron\task\base
{
protected $config;
protected $user;
/**
* Constructor.
*
* @param \phpbb\config\config $config The config
* @param \phpbb\user $user The user
*/
public function __construct(\phpbb\config\config $config, \phpbb\user $user)
{
$this->config = $config;
$this->user = $user;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
$this->user->session_gc();
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* The interval between session tidying is specified in board
* configuration.
*
* @return bool
*/
public function should_run()
{
return $this->config['session_last_gc'] < time() - $this->config['session_gc'];
}
}

View File

@ -0,0 +1,80 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task\core;
/**
* Tidy warnings cron task.
*
* Will only run when warnings are configured to expire.
*/
class tidy_warnings extends \phpbb\cron\task\base
{
protected $phpbb_root_path;
protected $php_ext;
protected $config;
/**
* Constructor.
*
* @param string $phpbb_root_path The root path
* @param string $php_ext PHP file extension
* @param \phpbb\config\config $config The config
*/
public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
$this->config = $config;
}
/**
* Runs this cron task.
*
* @return null
*/
public function run()
{
if (!function_exists('tidy_warnings'))
{
include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);
}
tidy_warnings();
}
/**
* Returns whether this cron task can run, given current board configuration.
*
* If warnings are set to never expire, this cron task will not run.
*
* @return bool
*/
public function is_runnable()
{
return (bool) $this->config['warnings_expire_days'];
}
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* The interval between warnings tidying is specified in board
* configuration.
*
* @return bool
*/
public function should_run()
{
return $this->config['warnings_last_gc'] < time() - $this->config['warnings_gc'];
}
}

View File

@ -0,0 +1,130 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task\core;
/**
* Update old hashes to the current default hashing algorithm
*
* It is intended to gradually update all "old" style hashes to the
* current default hashing algorithm.
*/
class update_hashes extends \phpbb\cron\task\base
{
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\lock\db */
protected $update_lock;
/** @var \phpbb\passwords\manager */
protected $passwords_manager;
/** @var string Default hashing type */
protected $default_type;
/**
* Constructor.
*
* @param \phpbb\config\config $config
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\lock\db $update_lock
* @param \phpbb\passwords\manager $passwords_manager
* @param array $hashing_algorithms Hashing driver
* service collection
* @param array $defaults Default password types
*/
public function __construct(\phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\lock\db $update_lock, \phpbb\passwords\manager $passwords_manager, $hashing_algorithms, $defaults)
{
$this->config = $config;
$this->db = $db;
$this->passwords_manager = $passwords_manager;
$this->update_lock = $update_lock;
foreach ($defaults as $type)
{
if ($hashing_algorithms[$type]->is_supported())
{
$this->default_type = $type;
break;
}
}
}
/**
* {@inheritdoc}
*/
public function is_runnable()
{
return !$this->config['use_system_cron'];
}
/**
* {@inheritdoc}
*/
public function should_run()
{
if (!empty($this->config['update_hashes_lock']))
{
$last_run = explode(' ', $this->config['update_hashes_lock']);
if ($last_run[0] + 60 >= time())
{
return false;
}
}
return $this->config['enable_update_hashes'] && $this->config['update_hashes_last_cron'] < (time() - 60);
}
/**
* {@inheritdoc}
*/
public function run()
{
if ($this->update_lock->acquire())
{
$sql = 'SELECT user_id, user_password
FROM ' . USERS_TABLE . '
WHERE user_password ' . $this->db->sql_like_expression('$H$' . $this->db->get_any_char()) . '
OR user_password ' . $this->db->sql_like_expression('$CP$' . $this->db->get_any_char());
$result = $this->db->sql_query_limit($sql, 20);
$affected_rows = 0;
while ($row = $this->db->sql_fetchrow($result))
{
$new_hash = $this->passwords_manager->hash($row['user_password'], array($this->default_type));
// Increase number so we know that users were selected from the database
$affected_rows++;
$sql = 'UPDATE ' . USERS_TABLE . "
SET user_password = '" . $this->db->sql_escape($new_hash) . "'
WHERE user_id = " . (int) $row['user_id'];
$this->db->sql_query($sql);
}
$this->config->set('update_hashes_last_cron', time());
$this->update_lock->release();
// Stop cron for good once all hashes are converted
if ($affected_rows === 0)
{
$this->config->set('enable_update_hashes', '0');
}
}
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task;
/**
* Parametrized cron task interface.
*
* Parametrized cron tasks are somewhat of a cross between regular cron tasks and
* delayed jobs. Whereas regular cron tasks perform some action globally,
* parametrized cron tasks perform actions on a particular object (or objects).
* Parametrized cron tasks do not make sense and are not usable without
* specifying these objects.
*/
interface parametrized extends \phpbb\cron\task\task
{
/**
* Returns parameters of this cron task as an array.
*
* The array must map string keys to string values.
*
* @return array
*/
public function get_parameters();
/**
* Parses parameters found in $request, which is an instance of
* \phpbb\request\request_interface.
*
* $request contains user input and must not be trusted.
* Cron task must validate all data before using it.
*
* @param \phpbb\request\request_interface $request Request object.
*
* @return null
*/
public function parse_parameters(\phpbb\request\request_interface $request);
}

View File

@ -0,0 +1,52 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task;
/**
* Cron task interface
*/
interface task
{
/**
* Returns the name of the task.
*
* @return string Name of wrapped task.
*/
public function get_name();
/**
* Runs this cron task.
*
* @return null
*/
public function run();
/**
* Returns whether this cron task can run, given current board configuration.
*
* For example, a cron task that prunes forums can only run when
* forum pruning is enabled.
*
* @return bool
*/
public function is_runnable();
/**
* Returns whether this cron task should run now, because enough time
* has passed since it was last run.
*
* @return bool
*/
public function should_run();
}

View File

@ -0,0 +1,168 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task\text_reparser;
/**
* Reparse text cron task
*/
class reparser extends \phpbb\cron\task\base
{
const MIN = 1;
const SIZE = 100;
/**
* @var \phpbb\config\config
*/
protected $config;
/**
* @var \phpbb\config\db_text
*/
protected $config_text;
/**
* @var \phpbb\lock\db
*/
protected $reparse_lock;
/**
* @var \phpbb\textreparser\manager
*/
protected $reparser_manager;
/**
* @var string
*/
protected $reparser_name;
/**
* @var \phpbb\di\service_collection
*/
protected $reparsers;
/**
* @var array
*/
protected $resume_data;
/**
* Constructor
*
* @param \phpbb\config\config $config
* @param \phpbb\config\db_text $config_text
* @param \phpbb\lock\db $reparse_lock
* @param \phpbb\textreparser\manager $reparser_manager
* @param \phpbb\di\service_collection $reparsers
*/
public function __construct(\phpbb\config\config $config, \phpbb\config\db_text $config_text, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers)
{
$this->config = $config;
$this->config_text = $config_text;
$this->reparse_lock = $reparse_lock;
$this->reparser_manager = $reparser_manager;
$this->reparsers = $reparsers;
}
/**
* Sets the reparser for this cron task
*
* @param string $reparser
*/
public function set_reparser($reparser)
{
$this->reparser_name = !isset($this->reparsers[$reparser]) ? $this->reparser_manager->find_reparser($reparser) : $reparser;
if ($this->resume_data === null)
{
$this->resume_data = $this->reparser_manager->get_resume_data($this->reparser_name);
}
}
/**
* {@inheritdoc}
*/
public function is_runnable()
{
if ($this->resume_data === null)
{
$this->resume_data = $this->reparser_manager->get_resume_data($this->reparser_name);
}
if (!isset($this->resume_data['range-max']) || $this->resume_data['range-max'] >= $this->resume_data['range-min'])
{
return true;
}
return false;
}
/**
* {@inheritdoc}
*/
public function should_run()
{
if (!empty($this->config['reparse_lock']))
{
$last_run = explode(' ', $this->config['reparse_lock']);
if ($last_run[0] + 3600 >= time())
{
return false;
}
}
if ($this->config[$this->reparser_name . '_cron_interval'])
{
return $this->config[$this->reparser_name . '_last_cron'] < time() - $this->config[$this->reparser_name . '_cron_interval'];
}
return false;
}
/**
* {@inheritdoc}
*/
public function run()
{
if ($this->reparse_lock->acquire())
{
if ($this->resume_data === null)
{
$this->resume_data = $this->reparser_manager->get_resume_data($this->reparser_name);
}
/**
* @var \phpbb\textreparser\reparser_interface $reparser
*/
$reparser = $this->reparsers[$this->reparser_name];
$min = isset($this->resume_data['range-min']) ? $this->resume_data['range-min'] : self::MIN;
$current = isset($this->resume_data['range-max']) ? $this->resume_data['range-max'] : $reparser->get_max_id();
$size = isset($this->resume_data['range-size']) ? $this->resume_data['range-size'] : self::SIZE;
if ($current >= $min)
{
$start = max($min, $current + 1 - $size);
$end = max($min, $current);
$reparser->reparse_range($start, $end);
$this->reparser_manager->update_resume_data($this->reparser_name, $min, $start - 1, $size);
}
$this->config->set($this->reparser_name . '_last_cron', time());
$this->reparse_lock->release();
}
}
}

View File

@ -0,0 +1,106 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\cron\task;
/**
* Cron task wrapper class.
* Enhances cron tasks with convenience methods that work identically for all tasks.
*/
class wrapper
{
protected $task;
protected $phpbb_root_path;
protected $php_ext;
/**
* Constructor.
*
* Wraps a task $task, which must implement cron_task interface.
*
* @param \phpbb\cron\task\task $task The cron task to wrap.
* @param string $phpbb_root_path Relative path to phpBB root
* @param string $php_ext PHP file extension
*/
public function __construct(\phpbb\cron\task\task $task, $phpbb_root_path, $php_ext)
{
$this->task = $task;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
/**
* Returns whether the wrapped task is parametrised.
*
* Parametrized tasks accept parameters during initialization and must
* normally be scheduled with parameters.
*
* @return bool Whether or not this task is parametrized.
*/
public function is_parametrized()
{
return $this->task instanceof \phpbb\cron\task\parametrized;
}
/**
* Returns whether the wrapped task is ready to run.
*
* A task is ready to run when it is runnable according to current configuration
* and enough time has passed since it was last run.
*
* @return bool Whether the wrapped task is ready to run.
*/
public function is_ready()
{
return $this->task->is_runnable() && $this->task->should_run();
}
/**
* Returns a url through which this task may be invoked via web.
*
* When system cron is not in use, running a cron task is accomplished
* by outputting an image with the url returned by this function as
* source.
*
* @return string URL through which this task may be invoked.
*/
public function get_url()
{
$name = $this->get_name();
if ($this->is_parametrized())
{
$params = $this->task->get_parameters();
$extra = '';
foreach ($params as $key => $value)
{
$extra .= '&amp;' . $key . '=' . urlencode($value);
}
}
else
{
$extra = '';
}
$url = append_sid($this->phpbb_root_path . 'cron.' . $this->php_ext, 'cron_type=' . $name . $extra);
return $url;
}
/**
* Forwards all other method calls to the wrapped task implementation.
*
* @return mixed
*/
public function __call($name, $args)
{
return call_user_func_array(array($this->task, $name), $args);
}
}