Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
A time service was added to 8.3.x in #2717207: Add a time service to provide consistent interaction with time()/microtime() and superglobals.
Core code should be updated to remove deprecated uses of REQUEST_TIME and time() and others.
For more informations, see the change record.
Proposed resolution
Split this up into manageable chunks (#57 by @mpdonadio).
Remaining tasks
- #3113971: Replace REQUEST_TIME in services
- #3112298: Replace REQUEST_TIME in classes with direct container access
- #3395986: Replace REQUEST_TIME in plugins with direct container access
- #3112295: Replace REQUEST_TIME in rest of OO code (except for tests)
- #3112284: Replace REQUEST_TIME in Kernel tests
- #3309104: Replace REQUEST_TIME in Functional and FunctionalJavascript tests
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|
Comments
Comment #2
gigiabba CreditAttribution: gigiabba at Ibuildings commentedComment #4
zaporylieSo I see 3 active child issues where all 3 were blocked by @alexpott. I agree with Alex that we must consider a plan how we replace usage of REMOTE_TIME/time()/etc with datetime.time service. I also agree that we should think about usage scope rather than module/file/class.
IMO one of the ways of scoping this meta issue is to split them by the way how we use the service - either through static service container wrapper or dependency injection.
Comment #5
joachim CreditAttribution: joachim commented> In order to deprecate APIs in a maintainable way, converting deprecated uses should be replaced across all of core for a given kind of usage, rather than in individual modules or files. Such issues should also always be part of an overall plan to ensure all usages are removed, rather than standalone patches.
I don't understand this. The same policy is being applied to the issues to clean up coding standards, and it just means that works keeps stalling and not getting done.
Comment #6
zaporylieNot for the issues I've been working on. These were grouped by coding standard rule, rather than by the module, class or file.
Comment #7
zaporylieofftopic
Honestly - it sometimes takes a lot of time to reach the RTBC on an issue and then we are told this is all for nothing because we should do it in a different way from the beginning. It is what it is, though I agree with #5 that we could improve that process - give an early feedback to issues that go the wrong way at very early stage instead of waiting until RTBC before giving such a comment. Not sure how this can be done, though.
Comment #10
BerdirComment #11
pifagorprevious attempt https://www.drupal.org/project/drupal/issues/2858572
Comment #12
pifagorComment #13
pifagorComment #14
pifagorI added patch
Comment #15
pifagorComment #16
pifagorComment #17
Berdirthis is actually the documentation of the method itself, so this is kind a recursion now.
I'm not quite sure what to make of it, likely just remove that line. The can replace instances of part is a bit strange, but that's nor for this issue to improve (strange because it *is* the only proper way to access the time, not those others).
this shouldn't be replaced because time() is a php function, we can't deprecate that, just say that in most cases, this shoudl be used instead (which is what it does)
maybe documentation like this should say "the current time as query strang instead", aka focus on the concept, not the specific method call.
Comment #18
pifagorDear @berdir
I changed items 1 and 2.
As for item 3, I didn't quite understand how I need to change documentation, so I did not make any changes.
Comment #19
pifagorFixed small issue
Comment #20
volegerThe requests stack is empty in some cases so getCurrentTime goes to fail.
Also, there are a few places where time service called before container build.
Here introduced some changes, I hope this will fix a lot of failures.
Comment #21
volegerInterdiff
Comment #22
volegerReplacements should not be performed in the Unit tests as of the reason of container unavailability.
Here are reverts and some updates. See interdiff.
Comment #25
vladbo CreditAttribution: vladbo at EPAM Systems commentedFixes for the last failures.
Comment #26
pifagorComment #27
volegerReplacements still required:
core/modules/comment/comment.module:69
core/modules/history/history.module:24
Comment #28
pifagorHello @voleger
Here we can replace them only at
$_SERVER ['REQUEST_TIME']
. Since the change to\Drupal::time()->getRequestTime()
will cause a critical error.In my opinion, we also have to replace the define
define('COMMENT_NEW_LIMIT', REQUEST_TIME - 30 * 24 * 60 * 60)
anddefine('HISTORY_READ_LIMIT', REQUEST_TIME - 30 * 24 * 60 * 60)
with the method. But to do this in other issues, since the replacement in one patch HISTORY_READ_LIMIT, COMMENT_NEW_LIMIT, time(), REQUEST_TIME is not entirely the right solution.Comment #29
volegerI like the idea that each module should introduce own static method instead of the constant. This will allow using a service for the module needs.
Comment #30
vladbo CreditAttribution: vladbo at EPAM Systems commentedCOMMENT_NEW_LIMIT can be replaced by static method, but HISTORY_READ_LIMIT probably should be totally removed in these issues:
#2006632: Make HISTORY_READ_LIMIT configurable
#2355527: Make constant HISTORY_READ_LIMIT changeable
Comment #31
catchBumping priority and tagging.
Comment #33
JeroenTComment #34
JeroenTPatch needed reroll.
Comment #35
JeroenTRemoved some unrelated changes.
Comment #36
JeroenTAnd replaced another REQUEST_TIME call in \Drupal\search\SearchIndex.
Comment #37
JeroenTComment #38
JeroenTComment #39
mpdonadioFew comments. Didn't look at whole patch yet.
Should use the (int) cast to avoid floating point issues.
Should use the (int) cast to avoid floating point issues.
Should use the (int) cast to avoid floating point issues.
Should use the (int) cast to avoid floating point issues.
Comment #40
mpdonadiohttps://dispatcher.drupalci.org/job/drupal_patches/28837/console isn't showing anything useful for why #36 timed out, but it is possible that there is a test in an infinite loop now. @Mixlogic is here w/ me and I'll see if he has any thoughts.
PhpStorm gives this as the usage report after #36,
The history.module usage looks like it has the related issue.
The comment.module is used to define a new global constant, that isn't used any was slated to be removed (but no@deprecated; it was an old 8.0.x comment). See #2081585: [META] Modernize the History module
I think the remaining uses can be fixed in this issue.
Comment #41
mpdonadioWent back to #34 for this.
PhpStorm just reports the history.module and comment.module uses, and some update test fixtures (which are removed in 9).
Starting to look at the rest of the patch.
Comment #42
andypostIt has some conflicts with related
Comment #43
mpdonadioReverted a bunch on out of scope changes.
Comment #44
longwaveThis change seems out of scope.
Here we could reuse $timestamp on the second line to avoid two method calls.
This would probably just read better as "Default to request time when..."
Same here
I think we need to add this in a backward-compatible way?
"from the request time" is more simple to understand
This is a bit repetitive, I think we can just say "so the time won't change when cron runs".
Not sure this one should change, as we are passing REQUEST_TIME on?
Same as above
Would be simpler to get the time once and perhaps use
$timestamp++
on each line?Comment #45
mpdonadio#44, thanks for taking a look at this; everything you said makes sense. Few quick comments.
#5, that probably depends on whether we land in 8 or 9 with this (since this isn't marked as a critical). We can def do the BC way of adding a new service. That raises a bigger question.
I jumped into this a little late, but now recall why we didn't do this when we made the time service and deprecated that constant. It looks like the first version of the patch was a mostly search/replace (which valid approach for something this size to get to a passing patch). But, nearly all of the uses are using the \Drupal singleton and not DI. We need to make the decision about whether this is appropriate. I am wondering, even fore review sake, whether we need to split into three (or even four patches).
1. include files that need the $_SERVER thing.
2. tests; adjust KTB, BTB, and JSTB to add the service as a protected method and possible request time as a protected variable; this avoid a lot of calls to the singleton.
3. services/plugins should do proper DI
4. classes that don't have access to the container can use the singleton
That will make this easier to review, which will make it easier to get in. And, first one really is the important one to unblock progress on killing the includes issue. Then we can also do a f/up to nuke the calls to global time() and microtime().
?
Comment #46
longwave@mpdonadio I think your suggestion of splitting this up makes more sense; the order you suggested sounds good. I also think we might get stuck on part 3, but we can deal with that when we come to it; if we are going to do proper DI everywhere I don't think that will be viable in a single issue if we also have to do BC in constructors and add deprecation tests, there is just too much to change and review in one go.
Comment #47
mpdonadioOk, child issues are created w/ starting point patches, esstentially taking the #43 patch and then looking at results of `git diff --name-only 8.9.x` and then doing `git checkout 8.9.x ...` to revert changes unrelated to the child issue.
Assigned to datetime.module as we have historically used that for the greater date/time API and not just the module. Also assigned to myself as I hope to see all of these home.
Will remember to carryover credits later today.
Comment #48
BerdirThis one could be nasty.
We did the same in redis, but got some bug reports about errors: #3112364: Call to a member function get() on null in Drupal\\Component\\Datetime\\Time->getRequestTime().
I suspect right now that this happens for the internal page cache on pages that have an expiration time set, then the request time is not yet set up.
This isn't failing in core because nothing in core sets an expiration time on the internal page cache yet.
Comment #49
Berdir@catch and @alexpott agreed in Slack to postpone removing the constant to D10 as it seems like a lot of work is left that close to the first beta deadline. We can keep working on its removal in core but should also do an issue to change the deprecation message. And I guess remove it again from the hardcoded list in phpstan-drupal?
Comment #50
mpdonadioCreated #3113284: Move deprecation of REQUEST_TIME to Drupal 10 to address #49. Totally on board with this approach. If we end up using Symfony autowiring, then #3112298: Replace REQUEST_TIME in classes with direct container access may be easier. I also would't be surprised some of the fails in #3112284: Replace REQUEST_TIME in Kernel tests are from similar things (that issue is in my queue for this weekend).
Comment #51
mpdonadioWill also cleanup the IS to reflect the latest approach.
Comment #52
andypost++ to undeprecate it, moreover I think that remaining conversions slightly depends on request usage in controllers which still broken in many places starting from related, which could cause side-effects like in redis
Comment #53
Wim Leers#3113284: Move deprecation of REQUEST_TIME to Drupal 10 was committed.
Not entirely sure what this means for issue metadata … I think this?
Comment #54
catchSo we should still work on removing usages in 8.9.x, but since that's all happening in child issues it doesn't matter too much what version this is against.
This then becomes a Drupal 10 beta blocker eventually.
Comment #55
alexpottlooking at the problem with redis and page cache and middleware... I think the problem is happening because the request is only pushed onto the stack during \Drupal\Core\DrupalKernel::preHandle() - this means that any middleware that runs prior to \Drupal\Core\DrupalKernel::preHandle() will fail.
I think there are two options here...
1. Implement a fallback in \Drupal\Component\Datetime\Time() if the request is not available.
2. Add a very early middleware that sets a request on the Time service and use that instead.
Comment #56
alexpott#3113476: Fallback when request is not available on the stack in Time service addresses #55 and would allow all conversions to proceed without much bother.
Comment #57
mpdonadioPut a big dent into splitting this up into manageable chunks.
#3113971: Replace REQUEST_TIME in services
#3112298: Replace REQUEST_TIME in classes with direct container access
#3112295: Replace REQUEST_TIME in rest of OO code (except for tests)
#3112283: Replace REQUEST_TIME in non-OO and non-module code
are all ready for prelim review, even if there are fails.
#3112284: Replace REQUEST_TIME in Kernel tests
has fails, but would appreciate some thoughts on the approach and changes to KTB and BTB. This should be last to go in, anyway.
Comment #58
alexpottSo we've hit something interesting in [##3112295-18]
Here's the comment in full...
Oh fun... so at least the fail in
core/tests/Drupal/KernelTests/Core/Entity/ContentEntityChangedTest.php
happens because in KernelTestBase we do:Because it does
Request::create('/');
this ends up having a different time than $_SERVER['REQUEST_TIME'] (and therefore the legacy REQUEST_TIME) because this request is created using the result oftime()
not the server globals.I think this means efforts to do conversions bit by bit are fraught and that we might need to do everything at once.
Changing
Request::create('/');
toRequest::createFromGlobals();
fixes the test but I don't think this change is correct.Comment #59
mpdonadio#58, I am thinking that it could be as simple as
may do the trick, but I haven't tried this across all the child issues yet. I does consistently fix some of my local fails.
I think that all of these child issues
- need to be against the same branch; I think you were thinking 9.1 b/c the service definitions?
- need to sit at RTBC for a while to double check for spurious fails, and then commit at same time
Comment #60
jungleUpdating IS, changing the title a little bit and setting the status to Active. Unsigned @mpdonadio as no patch won't be accepted to inline with the title.
Comment #61
jungle#57 posted/splitted this 5 child issues from my understanding, but it's still unclear to me where is the child issue for modules/components. Or Do it here? I did visit the child issues mentioned in #57, two of them have an empty IS. Putting back the Needs issue summary update tag.
Comment #62
jungleThe background is I just closed #3111923: Deprecated REQUEST_TIME in Path Alias module in Drupal 9 as duplicate, But can not give an exact comment of which child issue they should continue and put their efforts on
Comment #63
andypostI found no views related issue, but Time cache plugin could use #3109110-6: Deprecate request argument for view time cache plugin
Comment #66
yogeshmpawarThere are few occurrences of
REQUEST_TIME
in install.core.inc file - https://git.drupalcode.org/project/drupal/-/blob/9.3.x/core/includes/ins... & https://git.drupalcode.org/project/drupal/-/blob/9.3.x/core/includes/ins...not sure in which issue we are targeting this, didn't find the exact issue so commenting here.
Comment #67
quietone CreditAttribution: quietone as a volunteer commentedLooks like it is in #3112283: Replace REQUEST_TIME in non-OO and non-module code.
Comment #68
TR CreditAttribution: TR commentedAdded #3112290: Replace REQUEST_TIME in procedural code to the issue summary.
Comment #69
mondrakeComment #71
andypostit still needs work for child issues, remaining deprecations will be removed in #3260778: Remove deprecated code from bootstrap.inc
Comment #72
daffie CreditAttribution: daffie commented#3112283: Replace REQUEST_TIME in non-OO and non-module code has landed.
Comment #74
Gábor HojtsySmall edits to issue summary to make keeping it up to date easier.
Comment #75
Gábor Hojtsy#3112283: Replace REQUEST_TIME in non-OO and non-module code and #3112290: Replace REQUEST_TIME in procedural code landed, so removing from remaining tasks.
Comment #76
Gábor HojtsyReparenting to #3213895: [META] Remove deprecated classes, methods, procedural functions and code paths outside of deprecated modules on the Drupal 10 branch.
Comment #77
catchMoving this under #3301204: Properly deprecate ajax.js methods since it's an incomplete deprecation rather than just removing deprecated code.
Comment #78
Gábor HojtsyThis also means that unless the subissues are resolved in time for Drupal 10 beta, the deprecation will be bumped to Drupal 11 as per discussion with @catch, so this is not a Drupal 10 beta requirement.
Comment #79
japerryThere seems to be an issue with the datetime.time service as well, as we cannot seem to access it when customers are defining their own cache containers. See #3302086: After upgrade to 2.4, Drupal 9.4.5 and PHP 8.0.21, \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. and #3113971: Replace REQUEST_TIME in services -- both of which would require releases in 9.5 and 10. So my vote would be punt this to 11.
Comment #82
Bhanu951 CreditAttribution: Bhanu951 as a volunteer commentedComment #83
Bhanu951 CreditAttribution: Bhanu951 as a volunteer commentedComment #84
Bhanu951 CreditAttribution: Bhanu951 as a volunteer commentedReferenced new issue #3309104: Replace REQUEST_TIME in Functional and FunctionalJavascript tests in summary.
Comment #85
Bhanu951 CreditAttribution: Bhanu951 as a volunteer commentedComment #86
quietone CreditAttribution: quietone as a volunteer commentedComment #87
acbramley CreditAttribution: acbramley at PreviousNext for Service NSW commentedHiding patches since this is now a meta.
Comment #88
andypostServices fixed #3113971: Replace REQUEST_TIME in services
Comment #89
acbramley CreditAttribution: acbramley at PreviousNext commented#3112295: Replace REQUEST_TIME in rest of OO code (except for tests) is the last of the issues! Once that's in I'll double check if there's any left and create a final cleanup if necessary. Great work everyone
Comment #90
andypostchecked - only mentions in comments are left
Comment #91
andypostLast issue fixed
Closing it in favor of follow-up to fix remaining mentions in comments #3422973: Replace remaining mentions of REQUEST_TIME in comments
Removed/re-titled a child issue as not a part of it #2908210: FIx TODO in Drupal\entity_test\Plugin\Field\FieldType\ChangedTestItem
Comment #92
andypostComment #93
kim.pepperCongrats everyone. Massive effort 💪
Comment #94
quietone CreditAttribution: quietone at PreviousNext commentedComment #95
acbramley CreditAttribution: acbramley at PreviousNext commentedComment #96
andypostComment #97
andypostClosed as duplicate #3030738: [meta] Replace usages of the deprecated REQUEST_TIME constant