aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/cron/task/wrapper.php
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2011-02-13 15:54:42 +0100
committerIgor Wiedler <igor@wiedler.ch>2011-02-13 15:54:42 +0100
commit04bd2e640e771948671ab6554df8962de980f511 (patch)
treed1e5a226ca875e940d1d98c710051d1911d8b2ad /phpBB/includes/cron/task/wrapper.php
parent8f0e9aee5ce518937b7ed05c2cd602e85e5b0b8a (diff)
parent1fd8d6de7f6bb41505530c83e487a9dc18bd25af (diff)
downloadforums-04bd2e640e771948671ab6554df8962de980f511.tar
forums-04bd2e640e771948671ab6554df8962de980f511.tar.gz
forums-04bd2e640e771948671ab6554df8962de980f511.tar.bz2
forums-04bd2e640e771948671ab6554df8962de980f511.tar.xz
forums-04bd2e640e771948671ab6554df8962de980f511.zip
Merge branch 'feature/system-cron' into develop
* feature/system-cron: (67 commits) [feature/system-cron] More tests for cron manager. [feature/system-cron] Added documentation for cron manager constructor. [feature/system-cron] Remove an unecessary assignment and an unecessary comment [feature/system-cron] Clarify comments about flush() call in cron. [feature/system-cron] preg_match returns int so cast to bool, fix comment [feature/system-cron] Rename lock() to acquire and unlock() to release. [feature/system-cron] Cache cron's task names. [feature/system-cron] Use a RecursiveDirectoryIterator instead of readdir. [feature/system-cron] Add array type hints if appropriate and remove globals. [feature/system-cron] Make use of the new config class in locks. [feature/system-cron] Fix duplicate instantiation of class loader in tests. [feature/system-cron] Abstract the database locking mechanism out of cron. [feature/system-cron] Move tests to phpunit.xml and always load class loader [feature/system-cron] Basic tests for cron manager. [feature/system-cron] Added @param/@return documentation [feature/system-cron] Add phpDoc documentation for everything else. [feature/system-cron] Cast result in cron_manager::is_valid_name() to bool. [feature/system-cron] Add phpDoc documentation for phpbb_cron_manager class. [feature/system-cron] Add phpDoc documentation for phpbb_cron_lock class. [feature/system-cron] Adjust SQL query style to follow coding guidelines. ...
Diffstat (limited to 'phpBB/includes/cron/task/wrapper.php')
-rw-r--r--phpBB/includes/cron/task/wrapper.php114
1 files changed, 114 insertions, 0 deletions
diff --git a/phpBB/includes/cron/task/wrapper.php b/phpBB/includes/cron/task/wrapper.php
new file mode 100644
index 0000000000..238d97853c
--- /dev/null
+++ b/phpBB/includes/cron/task/wrapper.php
@@ -0,0 +1,114 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Cron task wrapper class.
+* Enhances cron tasks with convenience methods that work identically for all tasks.
+*
+* @package phpBB3
+*/
+class phpbb_cron_task_wrapper
+{
+ /**
+ * Constructor.
+ *
+ * Wraps a task $task, which must implement cron_task interface.
+ *
+ * @param phpbb_cron_task $task The cron task to wrap.
+ */
+ public function __construct(phpbb_cron_task $task)
+ {
+ $this->task = $task;
+ }
+
+ /**
+ * Returns whether the wrapped task is parametrised.
+ *
+ * Parametrized tasks accept parameters during initialization and must
+ * normally be scheduled with parameters.
+ *
+ * @return bool Whether or not this task is parametrized.
+ */
+ public function is_parametrized()
+ {
+ return $this->task instanceof phpbb_cron_task_parametrized;
+ }
+
+ /**
+ * Returns whether the wrapped task is ready to run.
+ *
+ * A task is ready to run when it is runnable according to current configuration
+ * and enough time has passed since it was last run.
+ *
+ * @return bool Whether the wrapped task is ready to run.
+ */
+ public function is_ready()
+ {
+ return $this->task->is_runnable() && $this->task->should_run();
+ }
+
+ /**
+ * 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
+ * by outputting an image with the url returned by this function as
+ * source.
+ *
+ * @return string URL through which this task may be invoked.
+ */
+ public function get_url()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ $name = $this->get_name();
+ if ($this->is_parametrized())
+ {
+ $params = $this->task->get_parameters();
+ $extra = '';
+ foreach ($params as $key => $value)
+ {
+ $extra .= '&amp;' . $key . '=' . urlencode($value);
+ }
+ }
+ else
+ {
+ $extra = '';
+ }
+ $url = append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=' . $name . $extra);
+ return $url;
+ }
+
+ /**
+ * Forwards all other method calls to the wrapped task implementation.
+ *
+ * @return mixed
+ */
+ public function __call($name, $args)
+ {
+ return call_user_func_array(array($this->task, $name), $args);
+ }
+}