2010-04-17 03:13:30 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package phpBB3
|
|
|
|
* @copyright (c) 2010 phpBB Group
|
2011-12-31 13:32:52 +00:00
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
2010-04-17 03:13:30 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
if (!defined('IN_PHPBB'))
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cron manager class.
|
|
|
|
*
|
|
|
|
* Finds installed cron tasks, stores task objects, provides task selection.
|
|
|
|
*
|
|
|
|
* @package phpBB3
|
|
|
|
*/
|
2010-10-28 22:26:49 +02:00
|
|
|
class phpbb_cron_manager
|
2010-04-17 03:13:30 -04:00
|
|
|
{
|
2010-12-17 01:15:57 +01:00
|
|
|
/**
|
|
|
|
* Set of phpbb_cron_task_wrapper objects.
|
|
|
|
* Array holding all tasks that have been found.
|
|
|
|
*
|
2011-01-12 23:02:00 +01:00
|
|
|
* @var array
|
2010-12-17 01:15:57 +01:00
|
|
|
*/
|
2011-01-12 23:02:00 +01:00
|
|
|
protected $tasks = array();
|
|
|
|
|
2012-08-25 16:51:19 +02:00
|
|
|
protected $phpbb_root_path;
|
|
|
|
protected $php_ext;
|
2012-04-09 14:34:35 +02:00
|
|
|
|
2010-12-17 01:15:57 +01:00
|
|
|
/**
|
|
|
|
* Constructor. Loads all available tasks.
|
2011-01-13 00:51:32 +01:00
|
|
|
*
|
2012-04-09 00:22:55 +02:00
|
|
|
* @param array|Traversable $tasks Provides an iterable set of task names
|
2010-12-17 01:15:57 +01:00
|
|
|
*/
|
2012-07-26 16:15:56 +02:00
|
|
|
public function __construct($tasks, $phpbb_root_path, $php_ext)
|
2010-04-17 03:13:30 -04:00
|
|
|
{
|
2012-04-09 14:34:35 +02:00
|
|
|
$this->phpbb_root_path = $phpbb_root_path;
|
2012-07-26 16:15:56 +02:00
|
|
|
$this->php_ext = $php_ext;
|
2012-04-09 14:34:35 +02:00
|
|
|
|
2012-04-09 00:22:55 +02:00
|
|
|
$this->load_tasks($tasks);
|
2010-04-17 03:13:30 -04:00
|
|
|
}
|
|
|
|
|
2010-12-17 01:15:57 +01:00
|
|
|
/**
|
|
|
|
* Loads tasks given by name, wraps them
|
|
|
|
* and puts them into $this->tasks.
|
|
|
|
*
|
2012-04-09 00:22:55 +02:00
|
|
|
* @param array|Traversable $tasks Array of instances of phpbb_cron_task
|
2010-12-17 01:15:57 +01:00
|
|
|
*
|
2012-11-30 23:03:06 -05:00
|
|
|
* @return null
|
2010-12-17 01:15:57 +01:00
|
|
|
*/
|
2012-04-09 00:22:55 +02:00
|
|
|
public function load_tasks($tasks)
|
2010-04-17 03:13:30 -04:00
|
|
|
{
|
2012-04-09 00:22:55 +02:00
|
|
|
foreach ($tasks as $task)
|
2010-04-17 03:13:30 -04:00
|
|
|
{
|
2012-04-09 14:34:35 +02:00
|
|
|
$this->tasks[] = $this->wrap_task($task);
|
2010-04-17 03:13:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a task that is ready to run.
|
2010-12-19 23:56:43 +01:00
|
|
|
*
|
2010-04-17 03:13:30 -04:00
|
|
|
* If several tasks are ready, any one of them could be returned.
|
2010-12-17 01:15:57 +01:00
|
|
|
*
|
2010-12-19 23:56:43 +01:00
|
|
|
* If no tasks are ready, null is returned.
|
|
|
|
*
|
2010-12-17 01:15:57 +01:00
|
|
|
* @return phpbb_cron_task_wrapper|null
|
2010-04-17 03:13:30 -04:00
|
|
|
*/
|
2010-08-22 21:49:12 -04:00
|
|
|
public function find_one_ready_task()
|
2010-04-17 03:13:30 -04:00
|
|
|
{
|
|
|
|
foreach ($this->tasks as $task)
|
|
|
|
{
|
|
|
|
if ($task->is_ready())
|
|
|
|
{
|
|
|
|
return $task;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds all tasks that are ready to run.
|
2010-12-17 01:15:57 +01:00
|
|
|
*
|
2010-12-19 23:56:43 +01:00
|
|
|
* @return array List of tasks which are ready to run (wrapped in phpbb_cron_task_wrapper).
|
2010-04-17 03:13:30 -04:00
|
|
|
*/
|
2010-08-22 21:49:12 -04:00
|
|
|
public function find_all_ready_tasks()
|
2010-04-17 03:13:30 -04:00
|
|
|
{
|
|
|
|
$tasks = array();
|
|
|
|
foreach ($this->tasks as $task)
|
|
|
|
{
|
|
|
|
if ($task->is_ready())
|
|
|
|
{
|
|
|
|
$tasks[] = $task;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $tasks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds a task by name.
|
2010-12-19 23:56:43 +01:00
|
|
|
*
|
|
|
|
* If there is no task with the specified name, null is returned.
|
|
|
|
*
|
2010-04-17 03:13:30 -04:00
|
|
|
* Web runner uses this method to resolve names to tasks.
|
2010-12-17 01:15:57 +01:00
|
|
|
*
|
2010-12-19 23:56:43 +01:00
|
|
|
* @param string $name Name of the task to look up.
|
|
|
|
* @return phpbb_cron_task A task corresponding to the given name, or null.
|
2010-04-17 03:13:30 -04:00
|
|
|
*/
|
2010-08-22 21:49:12 -04:00
|
|
|
public function find_task($name)
|
2010-04-17 03:13:30 -04:00
|
|
|
{
|
|
|
|
foreach ($this->tasks as $task)
|
|
|
|
{
|
|
|
|
if ($task->get_name() == $name)
|
|
|
|
{
|
|
|
|
return $task;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2012-04-09 14:34:35 +02:00
|
|
|
|
2012-08-25 16:54:30 +02:00
|
|
|
/**
|
|
|
|
* Wraps a task inside an instance of phpbb_cron_task_wrapper.
|
|
|
|
*
|
|
|
|
* @param phpbb_cron_task $task The task.
|
|
|
|
* @return phpbb_cron_task_wrapper The wrapped task.
|
|
|
|
*/
|
2012-04-09 14:34:35 +02:00
|
|
|
public function wrap_task(phpbb_cron_task $task)
|
|
|
|
{
|
2012-07-26 16:15:56 +02:00
|
|
|
return new phpbb_cron_task_wrapper($task, $this->phpbb_root_path, $this->php_ext);
|
2012-04-09 14:34:35 +02:00
|
|
|
}
|
2010-04-17 03:13:30 -04:00
|
|
|
}
|