aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2012-04-09 14:34:35 +0200
committerIgor Wiedler <igor@wiedler.ch>2012-04-09 14:34:35 +0200
commit3896ee953fbdb45d0485c0b5dcdfca47409a22ed (patch)
tree86cee60150ff75d33332a60140230a4aaa780c97 /phpBB
parentaa0c995ed9cdafa2dfaca23b54d5b4cf6323f794 (diff)
downloadforums-3896ee953fbdb45d0485c0b5dcdfca47409a22ed.tar
forums-3896ee953fbdb45d0485c0b5dcdfca47409a22ed.tar.gz
forums-3896ee953fbdb45d0485c0b5dcdfca47409a22ed.tar.bz2
forums-3896ee953fbdb45d0485c0b5dcdfca47409a22ed.tar.xz
forums-3896ee953fbdb45d0485c0b5dcdfca47409a22ed.zip
[feature/dic] Give all cron tasks a name, change some manager usage
PHPBB3-10739
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/config/services.yml3
-rw-r--r--phpBB/cron.php2
-rw-r--r--phpBB/includes/cron/manager.php15
-rw-r--r--phpBB/includes/cron/task/base.php22
-rw-r--r--phpBB/includes/cron/task/provider.php7
-rw-r--r--phpBB/includes/cron/task/task.php7
-rw-r--r--phpBB/includes/cron/task/wrapper.php20
-rw-r--r--phpBB/viewforum.php8
8 files changed, 61 insertions, 23 deletions
diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml
index f6e92112f7..94d641ab8b 100644
--- a/phpBB/config/services.yml
+++ b/phpBB/config/services.yml
@@ -116,7 +116,8 @@ services:
class: phpbb_cron_manager
arguments:
- @cron.task_provider
- - @cache.driver
+ - %core.root_path%
+ - %core.php_ext%
cron.lock_db:
class: phpbb_lock_db
diff --git a/phpBB/cron.php b/phpBB/cron.php
index df48c2dc4d..be328db4de 100644
--- a/phpBB/cron.php
+++ b/phpBB/cron.php
@@ -61,7 +61,7 @@ function do_cron($cron_lock, $run_tasks)
if ($config['use_system_cron'])
{
- $cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver());
+ $cron = $container->get('cron.manager');
}
else
{
diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php
index 5abbc987dd..5ea909eb2c 100644
--- a/phpBB/includes/cron/manager.php
+++ b/phpBB/includes/cron/manager.php
@@ -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);
+ }
}
diff --git a/phpBB/includes/cron/task/base.php b/phpBB/includes/cron/task/base.php
index c05fb9a87c..94a2f267b4 100644
--- a/phpBB/includes/cron/task/base.php
+++ b/phpBB/includes/cron/task/base.php
@@ -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.
*
diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php
index acc3d455ec..9994d707f2 100644
--- a/phpBB/includes/cron/task/provider.php
+++ b/phpBB/includes/cron/task/provider.php
@@ -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);
diff --git a/phpBB/includes/cron/task/task.php b/phpBB/includes/cron/task/task.php
index 2f2a9e51f9..7b08fed413 100644
--- a/phpBB/includes/cron/task/task.php
+++ b/phpBB/includes/cron/task/task.php
@@ -22,6 +22,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.
*
* @return void
diff --git a/phpBB/includes/cron/task/wrapper.php b/phpBB/includes/cron/task/wrapper.php
index 66c45189e5..75b7fbdaa3 100644
--- a/phpBB/includes/cron/task/wrapper.php
+++ b/phpBB/includes/cron/task/wrapper.php
@@ -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;
}
/**
@@ -62,16 +66,6 @@ class phpbb_cron_task_wrapper
}
/**
- * 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.
*
* When system cron is not in use, running a cron task is accomplished
@@ -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;
}
diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php
index 16342ba1b3..25c8f5aa6d 100644
--- a/phpBB/viewforum.php
+++ b/phpBB/viewforum.php
@@ -193,10 +193,12 @@ if ($forum_data['forum_topics_per_page'])
// Do the forum Prune thang - cron type job ...
if (!$config['use_system_cron'])
{
- $task = $container->get('cron.task.core.prune_forum');
- $task = new phpbb_cron_task_wrapper($task);
+ $cron = $container->get('cron.manager');
+
+ $task = $cron->find_task('cron.task.core.prune_forum');
$task->set_forum_data($forum_data);
- if ($task && $task->is_ready())
+
+ if ($task->is_ready())
{
$url = $task->get_url();
$template->assign_var('RUN_CRON_TASK', '<img src="' . $url . '" width="1" height="1" alt="cron" />');