aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/cron
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/cron')
-rw-r--r--phpBB/phpbb/cron/controller/cron.php40
-rw-r--r--phpBB/phpbb/cron/event/cron_runner_listener.php103
-rw-r--r--phpBB/phpbb/cron/manager.php21
-rw-r--r--phpBB/phpbb/cron/task/core/update_hashes.php2
-rw-r--r--phpBB/phpbb/cron/task/wrapper.php47
5 files changed, 192 insertions, 21 deletions
diff --git a/phpBB/phpbb/cron/controller/cron.php b/phpBB/phpbb/cron/controller/cron.php
new file mode 100644
index 0000000000..6f0e35e4cd
--- /dev/null
+++ b/phpBB/phpbb/cron/controller/cron.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\cron\controller;
+
+use Symfony\Component\HttpFoundation\Response;
+
+/**
+ * Controller for running cron jobs
+ */
+class cron
+{
+ /**
+ * Handles CRON requests
+ *
+ * @param string $cron_type
+ *
+ * @return Response
+ */
+ public function handle($cron_type)
+ {
+ $response = new Response();
+ $response->headers->set('Cache-Control', 'no-cache');
+ $response->headers->set('Content-type', 'image/gif');
+ $response->headers->set('Content-length', '43');
+ $response->setContent(base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='));
+
+ return $response;
+ }
+}
diff --git a/phpBB/phpbb/cron/event/cron_runner_listener.php b/phpBB/phpbb/cron/event/cron_runner_listener.php
new file mode 100644
index 0000000000..9e9ecf0d47
--- /dev/null
+++ b/phpBB/phpbb/cron/event/cron_runner_listener.php
@@ -0,0 +1,103 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\cron\event;
+
+use phpbb\cron\manager;
+use phpbb\lock\db;
+use phpbb\request\request_interface;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\HttpKernel\Event\PostResponseEvent;
+
+/**
+ * Event listener that executes cron tasks, after the response was served
+ */
+class cron_runner_listener implements EventSubscriberInterface
+{
+ /**
+ * @var \phpbb\lock\db
+ */
+ private $cron_lock;
+
+ /**
+ * @var \phpbb\cron\manager
+ */
+ private $cron_manager;
+
+ /**
+ * @var \phpbb\request\request_interface
+ */
+ private $request;
+
+ /**
+ * Constructor
+ *
+ * @param db $lock
+ * @param manager $manager
+ * @param request_interface $request
+ */
+ public function __construct(db $lock, manager $manager, request_interface $request)
+ {
+ $this->cron_lock = $lock;
+ $this->cron_manager = $manager;
+ $this->request = $request;
+ }
+
+ /**
+ * Runs the cron job after the response was sent
+ *
+ * @param PostResponseEvent $event The event
+ */
+ public function on_kernel_terminate(PostResponseEvent $event)
+ {
+ $request = $event->getRequest();
+ $controller_name = $request->get('_route');
+
+ if ($controller_name !== 'phpbb_cron_run')
+ {
+ return;
+ }
+
+ $cron_type = $request->get('cron_type');
+
+ if ($this->cron_lock->acquire())
+ {
+ $task = $this->cron_manager->find_task($cron_type);
+ if ($task)
+ {
+ if ($task->is_parametrized())
+ {
+ $task->parse_parameters($this->request);
+ }
+
+ if ($task->is_ready())
+ {
+ $task->run();
+ }
+
+ $this->cron_lock->release();
+ }
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ static public function getSubscribedEvents()
+ {
+ return array(
+ KernelEvents::TERMINATE => 'on_kernel_terminate',
+ );
+ }
+}
diff --git a/phpBB/phpbb/cron/manager.php b/phpBB/phpbb/cron/manager.php
index 9bd30a0a5b..59ee693074 100644
--- a/phpBB/phpbb/cron/manager.php
+++ b/phpBB/phpbb/cron/manager.php
@@ -13,6 +13,9 @@
namespace phpbb\cron;
+use phpbb\cron\task\wrapper;
+use phpbb\routing\helper;
+
/**
* Cron manager class.
*
@@ -21,6 +24,11 @@ namespace phpbb\cron;
class manager
{
/**
+ * @var helper
+ */
+ protected $routing_helper;
+
+ /**
* Set of \phpbb\cron\task\wrapper objects.
* Array holding all tasks that have been found.
*
@@ -28,18 +36,27 @@ class manager
*/
protected $tasks = array();
+ /**
+ * @var string
+ */
protected $phpbb_root_path;
+
+ /**
+ * @var string
+ */
protected $php_ext;
/**
* Constructor. Loads all available tasks.
*
* @param array|\Traversable $tasks Provides an iterable set of task names
+ * @param helper $routing_helper Routing helper
* @param string $phpbb_root_path Relative path to phpBB root
* @param string $php_ext PHP file extension
*/
- public function __construct($tasks, $phpbb_root_path, $php_ext)
+ public function __construct($tasks, helper $routing_helper, $phpbb_root_path, $php_ext)
{
+ $this->routing_helper = $routing_helper;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
@@ -142,6 +159,6 @@ class manager
*/
public function wrap_task(\phpbb\cron\task\task $task)
{
- return new \phpbb\cron\task\wrapper($task, $this->phpbb_root_path, $this->php_ext);
+ return new wrapper($task, $this->routing_helper, $this->phpbb_root_path, $this->php_ext);
}
}
diff --git a/phpBB/phpbb/cron/task/core/update_hashes.php b/phpBB/phpbb/cron/task/core/update_hashes.php
index ba095abc8b..9e938f74dd 100644
--- a/phpBB/phpbb/cron/task/core/update_hashes.php
+++ b/phpBB/phpbb/cron/task/core/update_hashes.php
@@ -56,7 +56,7 @@ class update_hashes extends \phpbb\cron\task\base
foreach ($defaults as $type)
{
- if ($hashing_algorithms[$type]->is_supported())
+ if ($hashing_algorithms[$type]->is_supported() && !$hashing_algorithms[$type] instanceof \phpbb\passwords\driver\base_native)
{
$this->default_type = $type;
break;
diff --git a/phpBB/phpbb/cron/task/wrapper.php b/phpBB/phpbb/cron/task/wrapper.php
index 8a4a8b1f0c..4dc3a7fb95 100644
--- a/phpBB/phpbb/cron/task/wrapper.php
+++ b/phpBB/phpbb/cron/task/wrapper.php
@@ -13,14 +13,32 @@
namespace phpbb\cron\task;
+use phpbb\routing\helper;
+
/**
* Cron task wrapper class.
* Enhances cron tasks with convenience methods that work identically for all tasks.
*/
class wrapper
{
+ /**
+ * @var helper
+ */
+ protected $routing_helper;
+
+ /**
+ * @var task
+ */
protected $task;
+
+ /**
+ * @var string
+ */
protected $phpbb_root_path;
+
+ /**
+ * @var string
+ */
protected $php_ext;
/**
@@ -28,13 +46,15 @@ class wrapper
*
* Wraps a task $task, which must implement cron_task interface.
*
- * @param \phpbb\cron\task\task $task The cron task to wrap.
- * @param string $phpbb_root_path Relative path to phpBB root
- * @param string $php_ext PHP file extension
+ * @param task $task The cron task to wrap.
+ * @param helper $routing_helper Routing helper for route generation
+ * @param string $phpbb_root_path Relative path to phpBB root
+ * @param string $php_ext PHP file extension
*/
- public function __construct(\phpbb\cron\task\task $task, $phpbb_root_path, $php_ext)
+ public function __construct(task $task, helper $routing_helper, $phpbb_root_path, $php_ext)
{
$this->task = $task;
+ $this->routing_helper = $routing_helper;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
@@ -49,7 +69,7 @@ class wrapper
*/
public function is_parametrized()
{
- return $this->task instanceof \phpbb\cron\task\parametrized;
+ return $this->task instanceof parametrized;
}
/**
@@ -76,22 +96,13 @@ class wrapper
*/
public function get_url()
{
- $name = $this->get_name();
+ $params['cron_type'] = $this->get_name();
if ($this->is_parametrized())
{
- $params = $this->task->get_parameters();
- $extra = '';
- foreach ($params as $key => $value)
- {
- $extra .= '&amp;' . $key . '=' . urlencode($value);
- }
+ $params = array_merge($params, $this->task->get_parameters());
}
- else
- {
- $extra = '';
- }
- $url = append_sid($this->phpbb_root_path . 'cron.' . $this->php_ext, 'cron_type=' . $name . $extra);
- return $url;
+
+ return $this->routing_helper->route('phpbb_cron_run', $params);
}
/**