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.
This issue deals specifically with replace those calls in services.
The services that were identified to have those calls are:
- \Drupal\Core\Asset\JsCollectionRenderer
- \Drupal\Core\Cache\ApcuBackend
- \Drupal\Core\Cache\ApcuBackendFactory
- \Drupal\Core\Cache\DatabaseBackend
- \Drupal\Core\Cache\DatabaseBackendFactory
- \Drupal\Core\Cache\MemoryBackend
- \Drupal\Core\Cache\MemoryBackendFactory
- \Drupal\Core\Cache\MemoryCounterBackendFactory
- \Drupal\Core\Cache\PhpBackend
- \Drupal\Core\Cache\PhpBackendFactory
- \Drupal\Core\EventSubscriber\FinishResponseSubscriber
- \Drupal\Core\Flood\DatabaseBackend
- \Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory
- \Drupal\Core\Session\SessionHandler
- \Drupal\Core\Session\SessionManager
- \Drupal\comment\CommentStatistics
- \Drupal\path_alias\AliasManager
- \Drupal\search\SearchIndex
- \Drupal\update\UpdateProcessor
- \Drupal\user\EventSubscriber\UserRequestSubscriber
Proposed resolution
- Remove deprecated uses of REQUEST_TIME and time() and others.
- When this issue is successful, there should be no suppressions left in core/phpstan-baseline.neon for the above mentioned classes with the message Call to deprecated constant REQUEST_TIME: Deprecated in drupal:8.3.0 and is removed from drupal:11.0.0. Use \Drupal::time()->getRequestTime();
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3113971
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mpdonadioSmaller starting point.
Comment #3
mpdonadioLet the fails fly!
Comment #8
mpdonadioCommit credits.
Comment #9
daffie commentedTestbot is not happy
Comment #11
kristen polSee possibly related issues noted here:
https://www.drupal.org/project/drupal/issues/3112283#comment-13605217
Comment #12
pavnish commentedPatch re-rolled for 9.1.x Please review.
Comment #13
tanubansal commentedTested #12, Changes are visible in the above mentioned files
Comment #15
phenaproximaThis patch is really straightforward and clean. I did find a few small things...
Do we need deprecation notices in all of these, as per existing instances of this pattern in core? I suspect we do, but this is already a long patch...
This is changing the previous call to $this->state->get(). Out of scope?
Why isn't the time service injected here?
Same question here.
This seems a bit weird, honestly, but the weirdness doesn't originate in this patch, and refactoring it is probably out of scope. That said, shouldn't the time service be injected?
Let's say TimeInterface::getRequestTime() here, so that we're referring to an actual core API instead of a specific calling pattern.
Why isn't the time service injected here?
Can't we use the injected time service here?
Again, it's probably preferable to refer to TimeInterface::getRequestTime().
Nit: Missing a comma after $this->database.
The description must end with a period.
Comment #16
daffie commentedComment #17
phenaproximaSwitched us over to an issue fork: https://git.drupalcode.org/issue/drupal-3113971. Pushed patch #12 to it, fixing a merge conflict in the process. :) I'll try to address some of my own feedback in #15; it seems inefficient to wait for a new patch to be posted when so many of those complaints are relatively minor.
Comment #20
andypostit needs deprecation message to be cleared in next major
Comment #21
ravi.shankar commentedAdded reroll of patch #12 on Drupal 9.4.x.
Comment #22
murilohp commentedWorking on #12 and #20, I think @mpdonadio forgot to remove assign when he created this issue
Comment #23
mondrakeComment #24
murilohp commentedHey, I made this new patch, it's becoming huge and I tried to address all the points from #15 and #20, this patch still needs work, at least fix the failing tests and decide some stuff before move on.
Regarding #15:
Do we need deprecation notices in all of these, as per existing instances of this pattern in core? I suspect we do, but this is already a long patch...$time. We still need to cover all with tests, I've already created some tests, but there are more tests to add here in order to cover all the deprecation messages. So adding "Needs tests" tag hereThis is changing the previous call to $this->state->get(). Out of scope?Ok this is something that I think we have to discuss, the following classes are not really services:
core/lib/Drupal/Core/Cache/ApcuBackend.phpcore/lib/Drupal/Core/Cache/DatabaseBackend.phpcore/lib/Drupal/Core/Cache/MemoryBackend.phpcore/lib/Drupal/Core/Cache/PhpBackend.phpIn fact the factories are actually services and the idea is to construct the backend object, something like:
ApcuBackendFactory.phpconstructsApcuBackend.phpDatabaseBackendFactory.phpconstructsDatabaseBackend.phpMemoryBackendFactory.phpconstructsMemoryBackend.phpPhpBackendFactory.phpconstructsPhpBackend.phpSo, to get things right, I have some ideas:
CacheFactoryInterface::getfor more details).It would be nice to see your thoughts here, IMHO the backend classes are not part of the scope for this issue, I mean the idea here is to work on services, and that's not the case, just the factories are services, it would be nice to have an issue to address this.
Let's say TimeInterface::getRequestTime() here, so that we're referring to an actual core API instead of a specific calling pattern.Why isn't the time service injected here?Can't we use the injected time service here?Again, it's probably preferable to refer to TimeInterface::getRequestTime().Nit: Missing a comma after $this->database.The description must end with a period.Now moving to #20, I added a deprecated message and a new test to validated it.
So I guess that's it, there are some stuff that we need to do here, I'll leave this as need works.
FYI: Regarding the intediff, when I executed, I got a message,
interdiff: hunk-splitting is required in this case, but is not yet implemented, I don't know what happened, so I'm upload a diff usingdiff -u 21 24. Maybe it's a good idea to move this into the branch created by @phenaproxima to avoid this type of error.Thanks!
Comment #25
murilohp commentedComment #26
murilohp commentedRolling back
core/lib/Drupal/Core/Cache/ApcuBackend.phpdeprecated message.Comment #27
andypostCleaned-up a lot, mostly changed usage of time service to request-server-time for places where request stack already present.
Still fails few tests and I also added todos - makes sense to clean-up micro-optimizations from early days in follow-up or blocker issues.
Also removed unrelated changes - code style and function arguments clean-up
Removing tests tag as all coverage added for deprecated arguments
Comment #28
andypostneeds follow-up to prevent getting config in callback, it changes behavior so should get split
That's most PITA as this method is used a lot inside of loops and smells, needs separate issue to fix. I bet it could bring speed-up to runtime and tests
needs work
Comment #29
murilohp commentedHey @andypost, thanks for the response and the clean up, regarding #28:
FYI: The interdiff is actually a
diff -u, I'm having some issues locally to generate it, see #24.I'll leave this as NR, thanks!
Comment #30
murilohp commentedComment #31
andypostThank you but this approach causes tons tests to fail, that's why I suggest to move backends changes to separate issue
Exception: Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.Comment #32
daffie commentedI think that this change is a mistake.
__construct().Edit: I somehow removed the patch files from comment #29 and I have no idea how to put them back.
Comment #36
mondrakeWith autowiring, maybe this is now simpler? On it.
Comment #38
mondrakeI think we should limit the scope of this issue to core services only, and address module services separately.
Comment #39
spokjeNot arguing, but curious: In the current MR there are only 3 modules addressed, are these not all of them, because three seems a low number to split an issue on.
Comment #40
mondrakeJust because there are a few more core ones to address and the MR is getting fat. But yeah let’s see at the end.
Comment #41
mondrakePostponing on #3371840: Time::getRequestTime is not immutable when there is no request.
Comment #42
mondrakeThis will need some simplification once #3371840: Time::getRequestTime is not immutable when there is no request is in, and understanding why converting UpdateProcessor fails for UpdateSemverCoreTest.
Comment #43
andypostblocker commited
Comment #44
mondrakeI am working on this
Comment #45
mondrakejust rebase for now
Comment #46
andypostComment #47
mondrakeUnassigning, I will be afk for a few days.
Comment #48
spokjeDoing some grunt work.
Comment #49
spokjeComment #50
spokjeComment #51
spokjeGrunt work done:
- Updated IS.
- Added CR.
- Updated deprecation message and pointed to new CR.
- Used constructor property promotion.
- Made sure new
TimeInterface $timeconstructor parameter is not after optional constructor parameters.Thanks @voleger for the review.
Personal takeaways:
- There seems to be no mention nor method in our deprecation policy about adding constructor parameters needing to preceed optional constructor parameters.
- Service autowiring _really_ doesn't like union typehints.
- Unsure why when adding
autowire: trueto services we don't remove any existingarguments: ['@foo', '@bar']. They seem to be ignored when autowire is set to true, and (at least for me) add more confusion than help.Back to NR, so somebody who actually understands all of this can have a look :)
Comment #52
mondrake@Spokje thanks a lot for driving this to green again first of all.
I think we should not do the
autowire: true, at least not here. Better leave it to a dedicated issue. When I started using it it was more to see the effect, and I agree that given your findings, there are shadows with autowiring when there are optional parameters or deprecated ones, so let's not have that headache here.NW to remove
autowire: truefrom all the yml files and replace with explicit'@datetime.time'argument.Comment #53
spokjeThanks @mondrake, I misunderstood your afk-message as you being on holiday for a long(er) time and took the chance to mess your MR up ;)
Removed the autowiring, back to NR
Comment #54
mondrakeNo worries at all - thanks @Spokje!
Massive work!
I'd RTBC but cannot really. Will drop a thread in Slack to see if anyone's up for a review.
Comment #55
smustgrave commentedAll green and seems @mondrake has done a review so I'll lean on that.
Don't mind marking for yall.
Comment #56
taran2lSorry for being late to the party, but I have started before this issue was marked RTBC
Comment #57
spokjeComment #58
spokjeThanks for the review @Taran2L, applied 2 of your proposed changes, answered 2 others.
Back to NR.
Comment #59
smustgrave commentedleft a comment on MR.
Comment #60
spokjeComment #61
mondrakeAll points since previous RTBC were addressed, back to RTBC.
I am afraid if we don’t start getting these issues solved, we’d have to bring the deprecated define into D11.
Comment #62
mondrakeComment #63
mondrakerebased
Comment #64
spokjeWill sort this out (my) tomorrow morning, about 12hrs from now.
Comment #65
spokjeRebased and updated CR and deprecation errors to mention drupal:10.3.0.
Comment #66
quietone commentedNice to see this getting fixed.
I looked at this a few days ago and was put off by the size of the MR.,
64 files + 518 − 192. This is well above the recommended patch size. And thus there is a greater risk of introducing errors. However, since it more or less a lot of boilerplate I checked with the other release managers before replying.There is agreement that this needs to be re-scoped into smaller, manageable sizes. I will leave it up to the people working on this issue to create child issues that are easy to review.
Comment #67
spokjeWould a split between
\Drupal\Core\Cache\*and the rest work?Still probably (well) above the ideal patch size, but as said, it's mostly boilerplate code.
Comment #69
acbramley commentedAttempted a rebase, the services.yml conflicts with cache factories may have been incorrect.
Re #66 - is there an opportunity to bypass that requirement here? IMO the MR is not that difficult to review, it touches a lot of files but it is more than manageable. Splitting would require a bunch more busy work, conflict resolution, etc. These issues are already split into half a dozen issues from the meta and are all going to run into similar issue. As stated in #67 how would we even split it? There's no logical grouping here really.
Comment #71
smustgrave commentedSeems all threads have been addressed
Tests are still green and deprecation links seem fine. Not sure I've seen a generic CR cover so many classes before but also don't want to see a dozen CRs for the same.
LGTM! Going to mark as this appears to have gone through a number of reviews before.
Comment #72
catchThe MR has multiple merge conflicts so not committable.
Additionally I found multiple issues when reviewing - mostly nits but more than would have been fixable on commit.
@acbramley I'm agnostic about whether this is big enough to be split up, but definitely if it had been smaller in the first place it might have been easier to get in by now. While the changes are mostly boilerplate, they're not scannable find and replace stuff and I found things when reviewing. Whether it would be less work to split at this point is a different question (although if we did, then cache/non-cache seems fine as a split point).
Comment #73
acbramley commentedThanks @catch - my hope was to avoid more round trips and nasty conflicts again but this has bitten me badly now and we have some horrendous stuff to deal with now that #839444: Make serializer customizable for Cache\DatabaseBackend is in. I'm not even quite sure how to handle the now 2 new optional params in DatabaseBackend. That issue didn't take into account string $max_rows either (discussed in the MR on this issue).
Comment #74
andypostOnly one test failed!
Added 2 comments to help with #73
Comment #75
acbramley commentedThis is good to go again
Comment #76
andypostAdded fix for all constructors
https://git.drupalcode.org/project/drupal/-/merge_requests/4302/diffs?co...
Comment #77
acbramley commentedPHPCS is now failing... I don't understand why those variables had to change. They did not need to be fixed, proven by a green pipeline and my manual testing :)
Comment #78
andypostreverted useless change, only improved comments in my commit
Comment #79
smustgrave commentedNeeds a manual rebase now.
Comment #80
acbramley commentedRebased
Comment #81
smustgrave commentedAppears all feedback has been addressed.
Comment #83
catchI'm going to go ahead and commit this despite #66 because I've already reviewed it in its current state once and it's looking good now. However the re-roll hell this has been in since December validates that it probably would have been easier in smaller chunks - e.g. splitting cache changes out to their own issue, or core/modules changes or both. It's always hard to balance between too many changes in one issue vs. too many issues for one change, and can be hard to tell when you start working on an issue how big the eventual MR is going to end up, so very tricky to figure out.
Committed/pushed to 11.x, thanks everyone!
Comment #84
andypostThank you, CR looks updated, so could be published and MR removed
Comment #86
acbramley commentedThanks very much @catch