Problem/Motivation

REQUEST_TIME constant is marked as deprecated, see parent issue #2902895: [meta][no patch] Replace uses of REQUEST_TIME and time() with time service for full description.

User interface changes

No UI changes

API changes

Additional parameter (date/time service) added to cron service

Data model changes

No data model changes

Original report by @joachim:

The Cron service's setCronLastTime() method is using REQUEST_TIME. It should use the time service instead.

Comments

joachim created an issue. See original summary.

fazni’s picture

fazni’s picture

fazni’s picture

Status: Active » Needs review

Status: Needs review » Needs work
fazni’s picture

Status: Needs work » Needs review
fazni’s picture

Status: Needs review » Needs work
fazni’s picture

StatusFileSize
new552 bytes
fazni’s picture

Status: Needs work » Needs review
valthebald’s picture

Issue tags: +Vienna2017
valthebald’s picture

Status: Needs review » Needs work

The cron service gets a bunch of other services in its constructor. Can we inject time service in the same way (i.e. adding another constructor parameter)?

chenderson’s picture

I am working on this at DrupalCon Vienna

chenderson’s picture

Status: Needs work » Needs review
StatusFileSize
new2.87 KB

As suggested by valthebald I have added the time service into the constructor.

valthebald’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +@deprecated

Exactly what I was looking for, thank you @chenderson!

Adding issue summary, tagging, moving to RTBC

dawehner’s picture

+++ b/core/core.services.yml
@@ -345,7 +345,7 @@ services:
-    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

+++ b/core/lib/Drupal/Core/Cron.php
@@ -86,8 +94,10 @@ class Cron implements CronInterface {
-  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) {
     $this->moduleHandler = $module_handler;
     $this->lock = $lock;
     $this->queueFactory = $queue_factory;
@@ -95,6 +105,7 @@ public function __construct(ModuleHandlerInterface $module_handler, LockBackendI

@@ -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;
   }

We should make the $time parameter optional as otherwise code subclassing this class and overriding the constructor, would break.

chenderson’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.92 KB

@valthebald thanks :)

@dawehner I have made the $time parameter optional and have set the tests running.

Just wondering for future reference, is it required to run all the test variations for this type of change? Also I assume I needed change this back to 'Needs review' given the updated patch?

valthebald’s picture

@chenderson - there is no need to add all possible test combinations, default one is enough.
@dawehner - according to https://www.drupal.org/node/2562903#classes, only interfaces should be considered public API, and CronInterface does not set any expectations on constructor parameters

dawehner’s picture

Just an example: http://cgit.drupalcode.org/ultimate_cron/tree/src/UltimateCron.php?h=8.x...
I think avoiding BC breaks when we can easily is not really worth discussing :)

valthebald’s picture

Status: Needs review » Reviewed & tested by the community

@dawehner: oki-doki! :)

testbot is happy, I dare move the issue back to RTBC

Mixologic’s picture

Re #17 Thank you valdthebald. Testbot maintainer here trying to figure out why we're racking up such high costs. RTBC automatic retesting is running 14 tests a day.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed d26fe82 and pushed to 8.5.x. Thanks!

  • catch committed d26fe82 on 8.5.x
    Issue #2903551 by fazni, chenderson, valthebald, dawehner, joachim:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.