[feature/compiled-dic] Fix cron tasks again

PHPBB3-11152
This commit is contained in:
David King 2012-10-22 11:17:49 -04:00 committed by Igor Wiedler
parent cb2725dd5a
commit a6428c8dc3
4 changed files with 18 additions and 111 deletions

View file

@ -44,19 +44,15 @@ services:
- @cache.driver - @cache.driver
- %tables.config% - %tables.config%
cron.task_provider:
class: phpbb_cron_task_provider
arguments:
- @cron.task_collection
- @service_container
cron.task_collection: cron.task_collection:
class: phpbb_cron_task_collection class: phpbb_cron_task_collection
arguments:
- @service_container
cron.manager: cron.manager:
class: phpbb_cron_manager class: phpbb_cron_manager
arguments: arguments:
- @cron.task_provider - @cron.task_collection
- %core.root_path% - %core.root_path%
- %core.php_ext% - %core.php_ext%

View file

@ -15,58 +15,35 @@ if (!defined('IN_PHPBB'))
exit; exit;
} }
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
/** /**
* Collects cron tasks * Collects cron tasks
* *
* @package phpBB3 * @package phpBB3
*/ */
class phpbb_cron_task_collection implements ArrayAccess class phpbb_cron_task_collection extends ArrayObject
{ {
/** /**
* ArrayAccess method * Constructor
* *
* @param mixed $offset Array offset * @param TaggedContainerInterface $container Container object
*/ */
public function offsetExists($offset) public function __construct(TaggedContainerInterface $container)
{ {
return isset($this->tasks[$offset]); $this->container = $container;
} }
/** /**
* ArrayAccess method * Add a cron task to the collection
* *
* @param mixed $offset Array offset * @param string $name The service name of the cron task
* @return null
*/ */
public function offsetGet($offset) public function add($name)
{ {
return $this->offsetExists($offset) ? $this->tasks[$offset] : null; $task = $this->container->get($name);
} $task->set_name($name);
$this->offsetSet($name, $task);
/**
* ArrayAccess method
*
* @param mixed $offset Array offset
* @param mixed $value New value
*/
public function offsetSet($offset, $value)
{
if ($offset === null)
{
$this->tasks[] = $value;
}
else
{
$this->tasks[$offset] = $value;
}
}
/**
* ArrayAccess method
*
* @param mixed $offset Array offset
*/
public function offsetUnset($offset)
{
$this->tasks[$offset] = null;
} }
} }

View file

@ -1,66 +0,0 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
use Symfony\Component\DependencyInjection\TaggedContainerInterface;
/**
* Provides cron manager with tasks
*
* Finds installed cron tasks and makes them available to the cron manager.
*
* @package phpBB3
*/
class phpbb_cron_task_provider implements IteratorAggregate
{
private $tasks;
public function __construct(phpbb_cron_task_collection $tasks, TaggedContainerInterface $container)
{
$this->tasks = $tasks;
$this->container = $container;
}
/**
* Retrieve an iterator over all items
*
* @return ArrayIterator An iterator for the array of cron tasks
*/
public function getIterator()
{
$tasks = array();
foreach ($this->tasks as $names)
{
foreach ($names as $name)
{
if (!$this->container->has($name))
{
continue;
}
$task = $this->container->get($name);
if ($task instanceof phpbb_cron_task_base)
{
$task->set_name($name);
}
$tasks[] = $task;
}
}
return new ArrayIterator($tasks);
}
}

View file

@ -32,7 +32,7 @@ class phpbb_di_pass_cron implements CompilerPassInterface
foreach ($container->findTaggedServiceIds('cron.task') as $id => $data) foreach ($container->findTaggedServiceIds('cron.task') as $id => $data)
{ {
$definition->addMethodCall('offsetSet', array(null, $id)); $definition->addMethodCall('add', array($id));
} }
} }
} }