mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 22:10:45 +02:00
[feature/dic] Give all cron tasks a name, change some manager usage
PHPBB3-10739
This commit is contained in:
@@ -32,13 +32,18 @@ class phpbb_cron_manager
|
||||
*/
|
||||
protected $tasks = array();
|
||||
|
||||
protected $phpbb_root_path, $phpEx;
|
||||
|
||||
/**
|
||||
* Constructor. Loads all available tasks.
|
||||
*
|
||||
* @param array|Traversable $tasks Provides an iterable set of task names
|
||||
*/
|
||||
public function __construct($tasks)
|
||||
public function __construct($tasks, $phpbb_root_path, $phpEx)
|
||||
{
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->phpEx = $phpEx;
|
||||
|
||||
$this->load_tasks($tasks);
|
||||
}
|
||||
|
||||
@@ -54,8 +59,7 @@ class phpbb_cron_manager
|
||||
{
|
||||
foreach ($tasks as $task)
|
||||
{
|
||||
$wrapper = new phpbb_cron_task_wrapper($task);
|
||||
$this->tasks[] = $wrapper;
|
||||
$this->tasks[] = $this->wrap_task($task);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,4 +123,9 @@ class phpbb_cron_manager
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function wrap_task(phpbb_cron_task $task)
|
||||
{
|
||||
return new phpbb_cron_task_wrapper($task, $this->phpbb_root_path, $this->phpEx);
|
||||
}
|
||||
}
|
||||
|
@@ -28,6 +28,28 @@ if (!defined('IN_PHPBB'))
|
||||
*/
|
||||
abstract class phpbb_cron_task_base implements phpbb_cron_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.
|
||||
*
|
||||
|
@@ -45,7 +45,12 @@ class phpbb_cron_task_provider implements IteratorAggregate
|
||||
$tasks = array();
|
||||
foreach ($definitions as $name => $definition)
|
||||
{
|
||||
$tasks[] = $this->container->get($name);
|
||||
$task = $this->container->get($name);
|
||||
if ($task instanceof phpbb_cron_task_base) {
|
||||
$task->set_name($name);
|
||||
}
|
||||
|
||||
$tasks[] = $task;
|
||||
}
|
||||
|
||||
return new ArrayIterator($tasks);
|
||||
|
@@ -21,6 +21,13 @@ if (!defined('IN_PHPBB'))
|
||||
*/
|
||||
interface phpbb_cron_task
|
||||
{
|
||||
/**
|
||||
* Returns the name of the task.
|
||||
*
|
||||
* @return string Name of wrapped task.
|
||||
*/
|
||||
public function get_name();
|
||||
|
||||
/**
|
||||
* Runs this cron task.
|
||||
*
|
||||
|
@@ -23,6 +23,8 @@ if (!defined('IN_PHPBB'))
|
||||
*/
|
||||
class phpbb_cron_task_wrapper
|
||||
{
|
||||
private $task, $phpbb_root_path, $phpEx;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -30,9 +32,11 @@ class phpbb_cron_task_wrapper
|
||||
*
|
||||
* @param phpbb_cron_task $task The cron task to wrap.
|
||||
*/
|
||||
public function __construct(phpbb_cron_task $task)
|
||||
public function __construct(phpbb_cron_task $task, $phpbb_root_path, $phpEx)
|
||||
{
|
||||
$this->task = $task;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->phpEx = $phpEx;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,16 +65,6 @@ class phpbb_cron_task_wrapper
|
||||
return $this->task->is_runnable() && $this->task->should_run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of wrapped task. It is the same as the wrapped class's class name.
|
||||
*
|
||||
* @return string Class name of wrapped task.
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return get_class($this->task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a url through which this task may be invoked via web.
|
||||
*
|
||||
@@ -82,8 +76,6 @@ class phpbb_cron_task_wrapper
|
||||
*/
|
||||
public function get_url()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
$name = $this->get_name();
|
||||
if ($this->is_parametrized())
|
||||
{
|
||||
@@ -98,7 +90,7 @@ class phpbb_cron_task_wrapper
|
||||
{
|
||||
$extra = '';
|
||||
}
|
||||
$url = append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=' . $name . $extra);
|
||||
$url = append_sid($this->phpbb_root_path . 'cron.' . $this->phpEx, 'cron_type=' . $name . $extra);
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user