aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/cron/event
diff options
context:
space:
mode:
authorMáté Bartus <mate.bartus@gmail.com>2016-03-18 22:57:02 +0100
committerMarc Alexander <admin@m-a-styles.de>2019-05-06 21:45:15 +0200
commit7a173877b7244f4ab6a8ff7b6fa0d6450027751b (patch)
tree5f820d58f33a9e972815007dfc79494669d7e702 /phpBB/phpbb/cron/event
parent41956a8b9050fa6e1e301bfae51d947e6f13c068 (diff)
downloadforums-7a173877b7244f4ab6a8ff7b6fa0d6450027751b.tar
forums-7a173877b7244f4ab6a8ff7b6fa0d6450027751b.tar.gz
forums-7a173877b7244f4ab6a8ff7b6fa0d6450027751b.tar.bz2
forums-7a173877b7244f4ab6a8ff7b6fa0d6450027751b.tar.xz
forums-7a173877b7244f4ab6a8ff7b6fa0d6450027751b.zip
[ticket/14542] Move cron to controller
PHPBB3-14542
Diffstat (limited to 'phpBB/phpbb/cron/event')
-rw-r--r--phpBB/phpbb/cron/event/cron_runner_listener.php101
1 files changed, 101 insertions, 0 deletions
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..323ac966ac
--- /dev/null
+++ b/phpBB/phpbb/cron/event/cron_runner_listener.php
@@ -0,0 +1,101 @@
+<?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
+ */
+ 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',
+ );
+ }
+}