phpBB

Code Changes

File: phpbb/cron/manager.php

  Unmodified   Added   Modified   Removed
Line 15Line 15

use phpbb\cron\task\wrapper;
use phpbb\routing\helper;


use phpbb\cron\task\wrapper;
use phpbb\routing\helper;

 
use Symfony\Component\DependencyInjection\ContainerInterface;


/**
* Cron manager class.


/**
* Cron manager class.

Line 23Line 24
*/
class manager
{

*/
class manager
{

 
	/**
* @var ContainerInterface
*/
protected $phpbb_container;


	/**
* @var helper
*/

	/**
* @var helper
*/

Line 34Line 40
	*
* @var array
*/

	*
* @var array
*/

	protected $tasks = array();








	protected $tasks = [];

/**
* Flag indicating if $this->tasks contains tasks registered in the container
*
* @var bool
*/
protected $is_initialised_from_container = false;


/**
* @var string


/**
* @var string

Line 45Line 58
	 * @var string
*/
protected $php_ext;

	 * @var string
*/
protected $php_ext;

 

/**
* @var \phpbb\template\template
*/
protected $template;


/**
* Constructor. Loads all available tasks.
*


/**
* Constructor. Loads all available tasks.
*

	* @param array|\Traversable $tasks Provides an iterable set of task names

	* @param ContainerInterface $phpbb_container Container

	* @param helper $routing_helper Routing helper
* @param string $phpbb_root_path Relative path to phpBB root
* @param string $php_ext PHP file extension

	* @param helper $routing_helper Routing helper
* @param string $phpbb_root_path Relative path to phpBB root
* @param string $php_ext PHP file extension

 
	* @param \phpbb\template\template $template

	*/

	*/

	public function __construct($tasks, helper $routing_helper, $phpbb_root_path, $php_ext)

	public function __construct(ContainerInterface $phpbb_container, helper $routing_helper, $phpbb_root_path, $php_ext, $template)

	{

	{

 
		$this->phpbb_container = $phpbb_container;

		$this->routing_helper = $routing_helper;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;

		$this->routing_helper = $routing_helper;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;


$this->load_tasks($tasks);

		$this->template = $template;


	}

/**

	}

/**

Line 68Line 87
	* and puts them into $this->tasks.
*
* @param array|\Traversable $tasks Array of instances of \phpbb\cron\task\task

	* and puts them into $this->tasks.
*
* @param array|\Traversable $tasks Array of instances of \phpbb\cron\task\task

	*
* @return null

 
	*/
public function load_tasks($tasks)
{
foreach ($tasks as $task)
{
$this->tasks[] = $this->wrap_task($task);

	*/
public function load_tasks($tasks)
{
foreach ($tasks as $task)
{
$this->tasks[] = $this->wrap_task($task);

 
		}
}

/**
* Loads registered tasks from the container, wraps them
* and puts them into $this->tasks.
*/
public function load_tasks_from_container()
{
if (!$this->is_initialised_from_container)
{
$this->is_initialised_from_container = true;

$tasks = $this->phpbb_container->get('cron.task_collection');

$this->load_tasks($tasks);

		}
}


		}
}


Line 86Line 119
	*
* If no tasks are ready, null is returned.
*

	*
* If no tasks are ready, null is returned.
*

	* @return \phpbb\cron\task\wrapper|null

	* @return wrapper|null

	*/
public function find_one_ready_task()
{

	*/
public function find_one_ready_task()
{

 
		$this->load_tasks_from_container();


		shuffle($this->tasks);
foreach ($this->tasks as $task)
{

		shuffle($this->tasks);
foreach ($this->tasks as $task)
{

Line 108Line 143
	*/
public function find_all_ready_tasks()
{

	*/
public function find_all_ready_tasks()
{

		$tasks = array();



		$this->load_tasks_from_container();

$tasks = [];

		foreach ($this->tasks as $task)
{
if ($task->is_ready())

		foreach ($this->tasks as $task)
{
if ($task->is_ready())

Line 127Line 164
	* Web runner uses this method to resolve names to tasks.
*
* @param string $name Name of the task to look up.

	* Web runner uses this method to resolve names to tasks.
*
* @param string $name Name of the task to look up.

	* @return \phpbb\cron\task\wrapper	A wrapped task corresponding to the given name, or null.

	* @return wrapper	A wrapped task corresponding to the given name, or null.

	*/
public function find_task($name)
{

	*/
public function find_task($name)
{

 
		$this->load_tasks_from_container();


		foreach ($this->tasks as $task)
{
if ($task->get_name() == $name)

		foreach ($this->tasks as $task)
{
if ($task->get_name() == $name)

Line 148Line 187
	*/
public function get_tasks()
{

	*/
public function get_tasks()
{

 
		$this->load_tasks_from_container();


		return $this->tasks;
}


		return $this->tasks;
}


Line 155Line 196
	* Wraps a task inside an instance of \phpbb\cron\task\wrapper.
*
* @param \phpbb\cron\task\task $task The task.

	* Wraps a task inside an instance of \phpbb\cron\task\wrapper.
*
* @param \phpbb\cron\task\task $task The task.

	* @return \phpbb\cron\task\wrapper	The wrapped task.

	* @return wrapper	The wrapped task.

	*/
public function wrap_task(\phpbb\cron\task\task $task)
{

	*/
public function wrap_task(\phpbb\cron\task\task $task)
{

		return new wrapper($task, $this->routing_helper, $this->phpbb_root_path, $this->php_ext);

		return new wrapper($task, $this->routing_helper, $this->phpbb_root_path, $this->php_ext, $this->template);

	}
}


	}
}