1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-05 16:27:38 +02:00

[feature/compiled-dic] Fix cron task loading

We cannot use container tags at run time if we are using a cached, compiled
container object (i.e. phpbb_cache_container) so we have to load them
beforehand.

PHPBB3-11152
This commit is contained in:
David King
2012-10-21 16:09:43 -04:00
committed by Igor Wiedler
parent ad3edf505a
commit cb2725dd5a
8 changed files with 856 additions and 50 deletions

View File

@@ -0,0 +1,72 @@
<?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;
}
/**
* Collects cron tasks
*
* @package phpBB3
*/
class phpbb_cron_task_collection implements ArrayAccess
{
/**
* ArrayAccess method
*
* @param mixed $offset Array offset
*/
public function offsetExists($offset)
{
return isset($this->tasks[$offset]);
}
/**
* ArrayAccess method
*
* @param mixed $offset Array offset
*/
public function offsetGet($offset)
{
return $this->offsetExists($offset) ? $this->tasks[$offset] : null;
}
/**
* 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

@@ -26,10 +26,11 @@ use Symfony\Component\DependencyInjection\TaggedContainerInterface;
*/
class phpbb_cron_task_provider implements IteratorAggregate
{
private $container;
private $tasks;
public function __construct(TaggedContainerInterface $container)
public function __construct(phpbb_cron_task_collection $tasks, TaggedContainerInterface $container)
{
$this->tasks = $tasks;
$this->container = $container;
}
@@ -40,18 +41,24 @@ class phpbb_cron_task_provider implements IteratorAggregate
*/
public function getIterator()
{
$definitions = $this->container->findTaggedServiceIds('cron.task');
$tasks = array();
foreach ($definitions as $name => $definition)
foreach ($this->tasks as $names)
{
$task = $this->container->get($name);
if ($task instanceof phpbb_cron_task_base)
foreach ($names as $name)
{
$task->set_name($name);
}
if (!$this->container->has($name))
{
continue;
}
$tasks[] = $task;
$task = $this->container->get($name);
if ($task instanceof phpbb_cron_task_base)
{
$task->set_name($name);
}
$tasks[] = $task;
}
}
return new ArrayIterator($tasks);

View File

@@ -0,0 +1,38 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2012 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\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
class phpbb_di_pass_cron implements CompilerPassInterface
{
/**
* Modify the container before it is passed to the rest of the code
*
* @param ContainerBuilder $container ContainerBuilder object
* @return null
*/
public function process(ContainerBuilder $container)
{
$definition = $container->getDefinition('cron.task_collection');
foreach ($container->findTaggedServiceIds('cron.task') as $id => $data)
{
$definition->addMethodCall('offsetSet', array(null, $id));
}
}
}