From cb2725dd5a04118de8628e10f940e926f4fa8fa1 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 21 Oct 2012 16:09:43 -0400 Subject: [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 --- phpBB/includes/cron/task/collection.php | 72 +++++++++++++++++++++++++++++++++ phpBB/includes/cron/task/provider.php | 27 ++++++++----- 2 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 phpBB/includes/cron/task/collection.php (limited to 'phpBB/includes/cron/task') diff --git a/phpBB/includes/cron/task/collection.php b/phpBB/includes/cron/task/collection.php new file mode 100644 index 0000000000..d05be9012c --- /dev/null +++ b/phpBB/includes/cron/task/collection.php @@ -0,0 +1,72 @@ +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; + } +} diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php index 134723ebd1..08e54a651a 100644 --- a/phpBB/includes/cron/task/provider.php +++ b/phpBB/includes/cron/task/provider.php @@ -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); -- cgit v1.2.1 From a6428c8dc3c211675da5e7e58503849791d2d3e5 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 22 Oct 2012 11:17:49 -0400 Subject: [feature/compiled-dic] Fix cron tasks again PHPBB3-11152 --- phpBB/includes/cron/task/collection.php | 51 +++++++------------------ phpBB/includes/cron/task/provider.php | 66 --------------------------------- 2 files changed, 14 insertions(+), 103 deletions(-) delete mode 100644 phpBB/includes/cron/task/provider.php (limited to 'phpBB/includes/cron/task') diff --git a/phpBB/includes/cron/task/collection.php b/phpBB/includes/cron/task/collection.php index d05be9012c..84607dc28d 100644 --- a/phpBB/includes/cron/task/collection.php +++ b/phpBB/includes/cron/task/collection.php @@ -15,58 +15,35 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\DependencyInjection\TaggedContainerInterface; + /** * Collects cron tasks * * @package phpBB3 */ -class phpbb_cron_task_collection implements ArrayAccess +class phpbb_cron_task_collection extends ArrayObject { /** - * 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 + * Constructor * - * @param mixed $offset Array offset - * @param mixed $value New value + * @param TaggedContainerInterface $container Container object */ - public function offsetSet($offset, $value) + public function __construct(TaggedContainerInterface $container) { - if ($offset === null) - { - $this->tasks[] = $value; - } - else - { - $this->tasks[$offset] = $value; - } + $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 offsetUnset($offset) + public function add($name) { - $this->tasks[$offset] = null; + $task = $this->container->get($name); + $task->set_name($name); + $this->offsetSet($name, $task); } } diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php deleted file mode 100644 index 08e54a651a..0000000000 --- a/phpBB/includes/cron/task/provider.php +++ /dev/null @@ -1,66 +0,0 @@ -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); - } -} -- cgit v1.2.1 From 798c006e7fe55bc1de30e42a4c25e8c74911c865 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 10 Nov 2012 16:38:19 +0100 Subject: [ticket/11152] Convert cron_task_collection to generic di_service_collection PHPBB3-11152 --- phpBB/includes/cron/task/collection.php | 49 --------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 phpBB/includes/cron/task/collection.php (limited to 'phpBB/includes/cron/task') diff --git a/phpBB/includes/cron/task/collection.php b/phpBB/includes/cron/task/collection.php deleted file mode 100644 index 84607dc28d..0000000000 --- a/phpBB/includes/cron/task/collection.php +++ /dev/null @@ -1,49 +0,0 @@ -container = $container; - } - - /** - * Add a cron task to the collection - * - * @param string $name The service name of the cron task - * @return null - */ - public function add($name) - { - $task = $this->container->get($name); - $task->set_name($name); - $this->offsetSet($name, $task); - } -} -- cgit v1.2.1