diff options
Diffstat (limited to 'phpBB/phpbb/cron/task')
| -rw-r--r-- | phpBB/phpbb/cron/task/base.php | 70 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/core/prune_all_forums.php | 87 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/core/prune_forum.php | 157 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/core/prune_notifications.php | 59 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/core/queue.php | 76 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/core/tidy_cache.php | 70 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/core/tidy_database.php | 64 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/core/tidy_plupload.php | 116 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/core/tidy_search.php | 98 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/core/tidy_sessions.php | 57 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/core/tidy_warnings.php | 78 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/parametrized.php | 46 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/task.php | 49 | ||||
| -rw-r--r-- | phpBB/phpbb/cron/task/wrapper.php | 102 | 
14 files changed, 1129 insertions, 0 deletions
| diff --git a/phpBB/phpbb/cron/task/base.php b/phpBB/phpbb/cron/task/base.php new file mode 100644 index 0000000000..63f0407bcd --- /dev/null +++ b/phpBB/phpbb/cron/task/base.php @@ -0,0 +1,70 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +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. +* +* @package phpBB3 +*/ +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; +	} +} diff --git a/phpBB/phpbb/cron/task/core/prune_all_forums.php b/phpBB/phpbb/cron/task/core/prune_all_forums.php new file mode 100644 index 0000000000..90b9a5914b --- /dev/null +++ b/phpBB/phpbb/cron/task/core/prune_all_forums.php @@ -0,0 +1,87 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +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. +* +* @package phpBB3 +*/ +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 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; +	} + +	/** +	* 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, forum_flags, prune_freq +			FROM ' . FORUMS_TABLE . " +			WHERE enable_prune = 1 +				AND prune_next < " . time(); +		$result = $this->db->sql_query($sql); +		while ($row = $this->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']); +			} +		} +		$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']; +	} +} diff --git a/phpBB/phpbb/cron/task/core/prune_forum.php b/phpBB/phpbb/cron/task/core/prune_forum.php new file mode 100644 index 0000000000..e0d8b067c5 --- /dev/null +++ b/phpBB/phpbb/cron/task/core/prune_forum.php @@ -0,0 +1,157 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +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. +* +* @package phpBB3 +*/ +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_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_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; +			} +		} +	} +} diff --git a/phpBB/phpbb/cron/task/core/prune_notifications.php b/phpBB/phpbb/cron/task/core/prune_notifications.php new file mode 100644 index 0000000000..9f67c54e1c --- /dev/null +++ b/phpBB/phpbb/cron/task/core/prune_notifications.php @@ -0,0 +1,59 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\cron\task\core; + +/** +* Prune notifications cron task. +* +* @package phpBB3 +*/ +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']; +	} +} diff --git a/phpBB/phpbb/cron/task/core/queue.php b/phpBB/phpbb/cron/task/core/queue.php new file mode 100644 index 0000000000..cd799b8024 --- /dev/null +++ b/phpBB/phpbb/cron/task/core/queue.php @@ -0,0 +1,76 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\cron\task\core; + +/** +* Queue cron task. Sends email and jabber messages queued by other scripts. +* +* @package phpBB3 +*/ +class queue 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 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 (!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->phpbb_root_path . 'cache/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_config']; +	} +} diff --git a/phpBB/phpbb/cron/task/core/tidy_cache.php b/phpBB/phpbb/cron/task/core/tidy_cache.php new file mode 100644 index 0000000000..a94a85db53 --- /dev/null +++ b/phpBB/phpbb/cron/task/core/tidy_cache.php @@ -0,0 +1,70 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\cron\task\core; + +/** +* Tidy cache cron task. +* +* @package phpBB3 +*/ +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']; +	} +} diff --git a/phpBB/phpbb/cron/task/core/tidy_database.php b/phpBB/phpbb/cron/task/core/tidy_database.php new file mode 100644 index 0000000000..f712a5047c --- /dev/null +++ b/phpBB/phpbb/cron/task/core/tidy_database.php @@ -0,0 +1,64 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\cron\task\core; + +/** +* Tidy database cron task. +* +* @package phpBB3 +*/ +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 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']; +	} +} diff --git a/phpBB/phpbb/cron/task/core/tidy_plupload.php b/phpBB/phpbb/cron/task/core/tidy_plupload.php new file mode 100644 index 0000000000..5a98e0bd7b --- /dev/null +++ b/phpBB/phpbb/cron/task/core/tidy_plupload.php @@ -0,0 +1,116 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\cron\task\core; + +/** +* Cron task for cleaning plupload's temporary upload directory. +* +* @package phpBB3 +*/ +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; + +	/** +	* 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 +	*/ +	public function __construct($phpbb_root_path, \phpbb\config\config $config) +	{ +		$this->phpbb_root_path = $phpbb_root_path; +		$this->config = $config; + +		$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) +		{ +			add_log( +				'critical', +				'LOG_PLUPLOAD_TIDY_FAILED', +				$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; +	} +} diff --git a/phpBB/phpbb/cron/task/core/tidy_search.php b/phpBB/phpbb/cron/task/core/tidy_search.php new file mode 100644 index 0000000000..42f7df308f --- /dev/null +++ b/phpBB/phpbb/cron/task/core/tidy_search.php @@ -0,0 +1,98 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\cron\task\core; + +/** +* Tidy search cron task. +* +* Will only run when the currently selected search backend supports tidying. +* +* @package phpBB3 +*/ +class tidy_search extends \phpbb\cron\task\base +{ +	protected $phpbb_root_path; +	protected $php_ext; +	protected $auth; +	protected $config; +	protected $db; +	protected $user; + +	/** +	* Constructor. +	* +	* @param string $phpbb_root_path The root path +	* @param string $php_ext The PHP extension +	* @param \phpbb\auth\auth $auth The auth +	* @param \phpbb\config\config $config The config +	* @param \phpbb\db\driver\driver $db The db connection +	* @param \phpbb\user $user The user +	*/ +	public function __construct($phpbb_root_path, $php_ext, \phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver $db, \phpbb\user $user) +	{ +		$this->phpbb_root_path = $phpbb_root_path; +		$this->php_ext = $php_ext; +		$this->auth = $auth; +		$this->config = $config; +		$this->db = $db; +		$this->user = $user; +	} + +	/** +	* Runs this cron task. +	* +	* @return null +	*/ +	public function run() +	{ +		// Select the search method +		$search_type = basename($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); + +		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() +	{ +		// Select the search method +		$search_type = basename($this->config['search_type']); + +		return class_exists($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']; +	} +} diff --git a/phpBB/phpbb/cron/task/core/tidy_sessions.php b/phpBB/phpbb/cron/task/core/tidy_sessions.php new file mode 100644 index 0000000000..68094af1f7 --- /dev/null +++ b/phpBB/phpbb/cron/task/core/tidy_sessions.php @@ -0,0 +1,57 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\cron\task\core; + +/** +* Tidy sessions cron task. +* +* @package phpBB3 +*/ +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']; +	} +} diff --git a/phpBB/phpbb/cron/task/core/tidy_warnings.php b/phpBB/phpbb/cron/task/core/tidy_warnings.php new file mode 100644 index 0000000000..a0ff23fc57 --- /dev/null +++ b/phpBB/phpbb/cron/task/core/tidy_warnings.php @@ -0,0 +1,78 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\cron\task\core; + +/** +* Tidy warnings cron task. +* +* Will only run when warnings are configured to expire. +* +* @package phpBB3 +*/ +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 The PHP 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']; +	} +} diff --git a/phpBB/phpbb/cron/task/parametrized.php b/phpBB/phpbb/cron/task/parametrized.php new file mode 100644 index 0000000000..1aeead0399 --- /dev/null +++ b/phpBB/phpbb/cron/task/parametrized.php @@ -0,0 +1,46 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +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. +* +* @package phpBB3 +*/ +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); +} diff --git a/phpBB/phpbb/cron/task/task.php b/phpBB/phpbb/cron/task/task.php new file mode 100644 index 0000000000..3ce3de9598 --- /dev/null +++ b/phpBB/phpbb/cron/task/task.php @@ -0,0 +1,49 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\cron\task; + +/** +* Cron task interface +* @package phpBB3 +*/ +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(); +} diff --git a/phpBB/phpbb/cron/task/wrapper.php b/phpBB/phpbb/cron/task/wrapper.php new file mode 100644 index 0000000000..fc3f897206 --- /dev/null +++ b/phpBB/phpbb/cron/task/wrapper.php @@ -0,0 +1,102 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +namespace phpbb\cron\task; + +/** +* Cron task wrapper class. +* Enhances cron tasks with convenience methods that work identically for all tasks. +* +* @package phpBB3 +*/ +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. +	*/ +	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 .= '&' . $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); +	} +} | 
