Commit d26fe829 authored by catch's avatar catch

Issue #2903551 by fazni, chenderson, valthebald, dawehner, joachim: Replace...

Issue #2903551 by fazni, chenderson, valthebald, dawehner, joachim: Replace REQUEST_TIME with time service in cron service
parent 19fa2eb5
......@@ -345,7 +345,7 @@ services:
arguments: ['@service_container']
cron:
class: Drupal\Core\Cron
arguments: ['@module_handler', '@lock', '@queue', '@state', '@account_switcher', '@logger.channel.cron', '@plugin.manager.queue_worker']
arguments: ['@module_handler', '@lock', '@queue', '@state', '@account_switcher', '@logger.channel.cron', '@plugin.manager.queue_worker', '@datetime.time']
lazy: true
diff.formatter:
class: Drupal\Core\Diff\DiffFormatter
......
......@@ -2,6 +2,7 @@
namespace Drupal\Core;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Utility\Timer;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Queue\QueueWorkerManagerInterface;
......@@ -69,6 +70,13 @@ class Cron implements CronInterface {
*/
protected $queueManager;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* Constructs a cron object.
*
......@@ -86,8 +94,10 @@ class Cron implements CronInterface {
* A logger instance.
* @param \Drupal\Core\Queue\QueueWorkerManagerInterface $queue_manager
* The queue plugin manager.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
*/
public function __construct(ModuleHandlerInterface $module_handler, LockBackendInterface $lock, QueueFactory $queue_factory, StateInterface $state, AccountSwitcherInterface $account_switcher, LoggerInterface $logger, QueueWorkerManagerInterface $queue_manager) {
public function __construct(ModuleHandlerInterface $module_handler, LockBackendInterface $lock, QueueFactory $queue_factory, StateInterface $state, AccountSwitcherInterface $account_switcher, LoggerInterface $logger, QueueWorkerManagerInterface $queue_manager, TimeInterface $time = NULL) {
$this->moduleHandler = $module_handler;
$this->lock = $lock;
$this->queueFactory = $queue_factory;
......@@ -95,6 +105,7 @@ public function __construct(ModuleHandlerInterface $module_handler, LockBackendI
$this->accountSwitcher = $account_switcher;
$this->logger = $logger;
$this->queueManager = $queue_manager;
$this->time = $time ?: \Drupal::service('datetime.time');
}
/**
......@@ -143,7 +154,8 @@ public function run() {
*/
protected function setCronLastTime() {
// Record cron time.
$this->state->set('system.cron_last', REQUEST_TIME);
$request_time = $this->time->getRequestTime();
$this->state->set('system.cron_last', $request_time);
$this->logger->notice('Cron run completed.');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment