aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/cron/event/cron_runner_listener.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/cron/event/cron_runner_listener.php')
-rw-r--r--phpBB/phpbb/cron/event/cron_runner_listener.php103
1 files changed, 103 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..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',
+ );
+ }
+}