comparison core/lib/Drupal/Core/Cron.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children af1871eacc83
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php 1 <?php
2 2
3 namespace Drupal\Core; 3 namespace Drupal\Core;
4 4
5 use Drupal\Component\Datetime\TimeInterface;
5 use Drupal\Component\Utility\Timer; 6 use Drupal\Component\Utility\Timer;
6 use Drupal\Core\Extension\ModuleHandlerInterface; 7 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\Queue\QueueWorkerManagerInterface; 8 use Drupal\Core\Queue\QueueWorkerManagerInterface;
8 use Drupal\Core\Queue\RequeueException; 9 use Drupal\Core\Queue\RequeueException;
9 use Drupal\Core\State\StateInterface; 10 use Drupal\Core\State\StateInterface;
66 * The queue plugin manager. 67 * The queue plugin manager.
67 * 68 *
68 * @var \Drupal\Core\Queue\QueueWorkerManagerInterface 69 * @var \Drupal\Core\Queue\QueueWorkerManagerInterface
69 */ 70 */
70 protected $queueManager; 71 protected $queueManager;
72
73 /**
74 * The time service.
75 *
76 * @var \Drupal\Component\Datetime\TimeInterface
77 */
78 protected $time;
71 79
72 /** 80 /**
73 * Constructs a cron object. 81 * Constructs a cron object.
74 * 82 *
75 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler 83 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
84 * The account switching service. 92 * The account switching service.
85 * @param \Psr\Log\LoggerInterface $logger 93 * @param \Psr\Log\LoggerInterface $logger
86 * A logger instance. 94 * A logger instance.
87 * @param \Drupal\Core\Queue\QueueWorkerManagerInterface $queue_manager 95 * @param \Drupal\Core\Queue\QueueWorkerManagerInterface $queue_manager
88 * The queue plugin manager. 96 * The queue plugin manager.
89 */ 97 * @param \Drupal\Component\Datetime\TimeInterface $time
90 public function __construct(ModuleHandlerInterface $module_handler, LockBackendInterface $lock, QueueFactory $queue_factory, StateInterface $state, AccountSwitcherInterface $account_switcher, LoggerInterface $logger, QueueWorkerManagerInterface $queue_manager) { 98 * The time service.
99 */
100 public function __construct(ModuleHandlerInterface $module_handler, LockBackendInterface $lock, QueueFactory $queue_factory, StateInterface $state, AccountSwitcherInterface $account_switcher, LoggerInterface $logger, QueueWorkerManagerInterface $queue_manager, TimeInterface $time = NULL) {
91 $this->moduleHandler = $module_handler; 101 $this->moduleHandler = $module_handler;
92 $this->lock = $lock; 102 $this->lock = $lock;
93 $this->queueFactory = $queue_factory; 103 $this->queueFactory = $queue_factory;
94 $this->state = $state; 104 $this->state = $state;
95 $this->accountSwitcher = $account_switcher; 105 $this->accountSwitcher = $account_switcher;
96 $this->logger = $logger; 106 $this->logger = $logger;
97 $this->queueManager = $queue_manager; 107 $this->queueManager = $queue_manager;
108 $this->time = $time ?: \Drupal::service('datetime.time');
98 } 109 }
99 110
100 /** 111 /**
101 * {@inheritdoc} 112 * {@inheritdoc}
102 */ 113 */
141 /** 152 /**
142 * Records and logs the request time for this cron invocation. 153 * Records and logs the request time for this cron invocation.
143 */ 154 */
144 protected function setCronLastTime() { 155 protected function setCronLastTime() {
145 // Record cron time. 156 // Record cron time.
146 $this->state->set('system.cron_last', REQUEST_TIME); 157 $request_time = $this->time->getRequestTime();
158 $this->state->set('system.cron_last', $request_time);
147 $this->logger->notice('Cron run completed.'); 159 $this->logger->notice('Cron run completed.');
148 } 160 }
149 161
150 /** 162 /**
151 * Processes cron queues. 163 * Processes cron queues.