Chris@0: cron = $cron; Chris@0: $this->config = $config_factory->get('automated_cron.settings'); Chris@0: $this->state = $state; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Run the automated cron if enabled. Chris@0: * Chris@0: * @param \Symfony\Component\HttpKernel\Event\PostResponseEvent $event Chris@0: * The Event to process. Chris@0: */ Chris@0: public function onTerminate(PostResponseEvent $event) { Chris@0: $interval = $this->config->get('interval'); Chris@0: if ($interval > 0) { Chris@0: $cron_next = $this->state->get('system.cron_last', 0) + $interval; Chris@0: if ((int) $event->getRequest()->server->get('REQUEST_TIME') > $cron_next) { Chris@0: $this->cron->run(); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Registers the methods in this class that should be listeners. Chris@0: * Chris@0: * @return array Chris@0: * An array of event listener definitions. Chris@0: */ Chris@0: public static function getSubscribedEvents() { Chris@0: return [KernelEvents::TERMINATE => [['onTerminate', 100]]]; Chris@0: } Chris@0: Chris@0: }