Closed (fixed)
Project:
Drupal core
Version:
9.4.x-dev
Component:
datetime.module
Priority:
Major
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
9 Feb 2020 at 16:06 UTC
Updated:
30 May 2022 at 16:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mpdonadioTook the patch from 2902895-43.patch and
git checkout 8.9.x core/modules core/lib core/tests
git diff 8.9.x > 3112283-02.patch
which just leaves us with the changes to (git diff --name-only 8.9.x)
core/core.api.php
core/includes/bootstrap.inc
core/includes/common.inc
core/includes/install.core.inc
core/rebuild.php
So, instead of
1. include files that need the $_SERVER thing.
I think a better description of the scope is
1. replace REQUEST_TIME in non-OO and non-module code
Comment #3
mpdonadioReroll b/c change in UserBlocksTest.
Comment #8
mpdonadioCommit credits.
Comment #9
daffie commentedAll changes look good to me.
For me it is RTBC.
Comment #10
alexpottCan this use \Drupal::time() now? Also if we can't I think using time() is better than doing
$_SERVER['REQUEST_TIME']- also there is no need to cast to int. it is an int.Comment #11
ravi.shankar commentedHere I have made changes as suggested in comment #10
Comment #12
daffie commented@ravi.shankar: Did you try the change that @alexpott suggested in comment #10 with
\Drupal::time()->getCurrentTime()instead oftime(). If you did and it did not work then it is for me RTBC.Comment #13
ravi.shankar commentedHi @daffie,
Unfortunately, I didn't try \Drupal::time()
I'll give it a try now.
Comment #14
ravi.shankar commentedHere I have added a new patch.
Comment #15
daffie commentedThe patch with
\Drupal::time()->getCurrentTime()instead oftime()did not work. Re uploading the patch from comment #11. That patch addresses the change that @alexpott would like. Therefor is that patch for me RTBC.Comment #16
alexpottThis needs to be the request time. I'm guessing that because \Drupal is not working this method is being called when there is no container. Changing this to
time()still doesn't buy us the test-ability that something \Drupal::time() would. Istime()better than$_SERVER['REQUEST_TIME']- i dunno - this feels like it is normally about validating a request made during a test so request time is more logical.All this said another issue converting to the \Drupal::time() service caused a lot of random fails so I'm not sure that the plan to do the conversions piecemeal is a good one because there are situations (especially another kernel tests) where
$_SERVER['REQUEST_TIME'] !== \Drupal::time()->getRequestTime()- see #2902895-58: [meta][no patch] Replace uses of REQUEST_TIME and time() with time serviceComment #17
alexpottIf we want to resolve the problem of testability for
drupal_valid_test_ua()then we need to pass the request into this method. If we did that we should get the request time form that object. So let's file another issue to do that.Comment #19
kristen polI see a lot of similar issues with changing REQUEST_TIME so I'm adding them as related issues (though I may have missed some). I'm unclear why so many were opened separately and without a lot of digging, I don't know if any can be closed as duplicates but it's likely some could be.
Comment #20
ptmkenny commentedFor anyone looking for an explanation of why there are several issues on this, see the discussion in the parent issue.
Comment #24
andypostComment #25
ravi.shankar commentedAdded reroll of patch #15 on Drupal 9.4.x.
Comment #26
mondrakeComment #27
andypostshould be moved out of loop
should use a variable to not call service twice
I think this place should use request->server->getInt(REQUEST_TIME)
Comment #28
ravi.shankar commentedMade changes as per comment #27, please review.
Comment #29
cliddell commentedThanks for working on this ravi! I think there's still a few more changes which need to be made.
You need to pass
REQUEST_TIMEas a string, not a constant since the constant is being deprecated. Passing'REQUEST_TIME'tells the request object, "Hey, I want the time of this request as an integer". So, this should really be$request->server->getInt('REQUEST_TIME').This should really be updated as well with
\Drupal::time()->getRequestTime());.This should be updated with either
$_SERVER['REQUEST_TIME']or maybetime(). Iftime()is used, I'd recommend setting the variable outside of the loop to prevent repeated calls totime().Comment #30
andregp commentedI'm gonna work on @cliddell suggestions at #29. :)
Comment #31
andregp commentedPatch updated with @cliddell suggestions.
Comment #32
jhedstromI'm not sure
$_SERVER['REQUEST_TIME']is ever set in this script? It might be safer to usetime()as noted above, or explicitly set$_SERVER['REQUEST_TIME'] = time()at the top of the script where other$_SERVERvalues are set...Comment #33
jhedstromActually, I think PHP always sets
$_SERVER['REQUEST_TIME'), so #32 can be ignored.Comment #34
jhedstromI think #31 is good to go.
Comment #35
alexpottCommitted 10dce7b and pushed to 10.0.x. Thanks!
Committed and pushed debf702718 to 9.5.x and 960480f092 to 9.4.x. Thanks!
On Drupal 10 has to make the above changes to commit this one. Given that core/phpstan-baseline.neon is automatically generated and the skips are obvious I think it is fine to do on commit.