Problem/Motivation
As part of #2999721: [META] Deprecate the legacy include files before Drupal 9, we want to deprecate drupal_set_time_limit()
and file_upload_max_size()
and move them to the Environment component.
Proposed resolution
- Move drupal_set_time_limit() from common.inc to Environment::setTimeLimit($time_limit);
- Move file_upload_max_size() from file.inc to Environment::getUploadMaxSize()
- Deprecate old functions
- Add trigger_error's for the deprecations
- Add tests for the deprecations
Remaining tasks
None.
User interface changes
None.
API changes
Two new methods on \Drupal\Component\Utility\Environment
Data model changes
Node.
Comment | File | Size | Author |
---|---|---|---|
#30 | 3000057-30.patch | 18.07 KB | kim.pepper |
Comments
Comment #2
claudiu.cristeaPatch.
Comment #3
longwaveDo we even strictly need this? Can't we just deprecate and suggest people use the built in functions directly?
The 240 seconds in node.module feels a bit arbitrary as well.
Comment #4
andypostBtw it more about Environment then php itself
Comment #5
andypostIf we do new implementation that let's polish it a bit
why error is not handled in new implementation, it makes sense to return success status from function call at least
Comment #6
dawehnerI am also wondering whether this could belong into
\Drupal\Component\Utility
?Comment #7
claudiu.cristea@dawehner, my understanding is that components are self-contained units that can be used also by other non-Drupal apps. I don't know if it is the case.
Comment #8
borisson_I think it does belong in Utility, this is something that can be used in another application without needing any other drupal things.
Comment #9
dawehnerI struggle a bit how utility becomes our dumping ground for all things we can't put into a better place.
On the other hand, this allows us to potentially see an order.
Comment #10
jcnventura CreditAttribution: jcnventura at Wunder commentedAs per #6, #8 and #9, it seems creating a new class is not desirable.
Comment #11
volegerRerolled.
Addressed #10
Comment #12
volegerComment #13
BerdirWhat about adding it to \Drupal\Component\Utility\Environment? That already has a php settings/memory limit method, so I think this would work quite well there?
Comment #14
kim.pepperI re-rolled #11 and moved it to Environment as @Berdir suggested. Makes more sense there I think.
Also, we plan on moving file_upload_max_size() here too, which I will do in the next patch.
Comment #15
kim.pepperThis moves file_upload_max_size() to \Drupal\Component\Utility\Environment::getUploadMaxSize() and deprecates it.
Comment #17
kim.pepperFix FormBuilder.
Comment #18
kim.pepperNeed to update the IS and CR if we are going down this path.
Comment #19
claudiu.cristeaLooks good, just a question:
Why do we keep this protected method? It was designed only to wrap the procedural function call.
Settings to NR for IS & CR update.
Comment #20
claudiu.cristeaOops
Comment #21
Berdir> Why do we keep this protected method? It was designed only to wrap the procedural function call.
Was about to post the same, but sometimes these kind of functions are then mocked and used to provide different values.
Comment #22
kim.pepperYep, that's exactly what FormBuilderTest is doing.
I've updated the title, IS and CR.
Comment #23
BerdirOk, then lets see what others think about my suggestion to move them to the Environment class. I've also fixed the wrong namespace in the CR.
Comment #24
dwwFWIW, +1 to expanding Environment instead of adding a whole new Component.
"Provides PHP environment helper methods." says the phpDoc for that class. That's what these are. ;)
No time for a careful review of #17 but given who's participating in here, I assume it's fine. ;) If I get a chance I'll take a closer look later today.
Thanks,
-Derek
Comment #25
mondrakeFWIW, in #3000050: Replace \Drupal\Component\Utility\Environment::checkMemoryLimit with a PHP memory checking helper class and service I was suggesting to move the existing Environment class to an instantiable one so that it could be unit tested with mocks. The concept there was to enable testing memory checks outside of real PHP memory. With static methods that's not possible https://github.com/sebastianbergmann/phpunit-documentation/issues/77.
Comment #26
dwwHad a chance for a deeper look. Overall, still +1 to this. All I have I are nits:
Environment
, but I wonder if we should do them in separate issues to make them easier to review/commit? Maybe we should have kept thefile_upload_max_size()
work at #3021652: Deprecate upload-related functions file.inc and move to a file upload service instead of merging into this patch? *shrug*All of this is unrelated and makes the patch harder to read. Maybe this should be spun off to a novice CS follow-up?
This comment is no longer true given #5. We no longer use
@set_time_limit()
and we are returning FALSE if the function doesn't exist or if it fails.Maybe just "An integer time limit in seconds, or 0 for unlimited execution time." ? That'd probably fit on a single line.
Maybe just: "Whether set_time_limit() was successful or not." ?
Missing " settings." at the end.
More noise potentially for a follow-up.
Doesn't this want a 1-liner before the @expectedDeprecation message?
And here.
Maybe also NW to consider #25 which seems like a legit request.
Thanks!
-Derek
Comment #27
dwwp.s. In other deprecation-related issues I've seen, we seem to rip out the full docblock for the deprecated function and leave the bare-bones: 1-liner, @params and @return. But the gory details are purged. *shrug*
Comment #28
kim.pepperRe #27 In the deprecation issues I've worked on, we've kept the full docblock. Not sure whether there is a preferred way?
Re #25 making this an class to be created each time it is used won't necessarily solve your problems. It's unlikely you would want to inject a utility component, and thereby be able to mock it. Instead I would follow the example of FormBuilder which has a protected function getFileUploadMaxSize() method which wraps Environment::getUploadMaxSize() and then mocks it out in FormBuilderTest.
Comment #29
dww1. Fair enough. Let's see what the core maintainers say.
2. Okay. I've seen folks NW patches for similar, but if the core committers are happy, so am I. ;)
3. Indeed, I linked to #5 in my comment. Was just pointing out we needed to change the comment in this case since we're changing the behavior.
4: Dang, you missed. ;) You "fixed" the wrong comment:
I was talking about the @param in the phpDoc above.
5-6: Thanks!
7: Cool.
8-9: *shrug*. The existing test in
core/tests/Drupal/KernelTests/Core/Common/LegacyFunctionsTest.php
does this:Re: #27 dunno. I guess core committers will decide.
Re: #25 Good point! Thanks for addressing.
So, only NW for re-fixing 4. Then this is RTBC to my eyes.
Thanks!
-Derek
Comment #30
kim.pepper4. Ooops! Fixed.
Thanks!
Comment #32
kim.pepper"Checkout Error". Re-running #30
Comment #33
dwwinterdiff looks great
Unless the bot objects, this is now RTBC.
Thanks!
-Derek
Comment #34
BerdirNote to committers, make sure you check comment #25 and that issue which conflicts with this, before committing this, we should make a decision about whether the Environment class should remain static or not. We could do both issues (deprecate the existing method and add more static methods, but possibly that doesn't make too much sense.
As I wrote there, the patch in the other issue seems a bit over-engineered for the pretty simple thing it does, with lots of methods, but that's just my first impression.
Comment #35
andypostLooking on usage of
Environment::checkMemoryLimit()
in core it's clear that most of time second parameter is not needed, so refactoring of this method makes sense but other issues statesBut current function already do that and I also feel like no reason to make it so complicated just to fix #2583041: GD toolkit & operations should catch \Throwable to fail gracefully in case of errors
Comment #36
larowlanAdding tags in relation to #34
Will flag with other FMs
Comment #37
larowlanMy 2c - creating the class that can be instantiated purely for testing sake (i.e with no concrete use case in production) feels like overkill
Can we call ini_set before the test to simulate the required mocked behaviour?
Comment #38
alexpottThis is a wrapper for the procedural function - and so it can be deprecated and the call to it replaced with
Environment::getUploadMaxSize()
For me we should postpone #3000050: Replace \Drupal\Component\Utility\Environment::checkMemoryLimit with a PHP memory checking helper class and service on this as this is making concrete changes and deprecating code.
Comment #39
kim.pepper@alexpott we need that in order for FormBuilderTest to stub a getUploadMaxSize() return value.
Re: #37 we can't call ini_set for `post_max_size` or `upload_max_filesize` because that is a PHP_INI_PERDIR mode: "Entry can be set in php.ini, .htaccess, httpd.conf or .user.ini "
Comment #40
dwwRe: #38 -- Indeed, @kim.pepper addresses it in #39, as was already stated at the end of #28. I don't think we should deprecate this. No real harm in leaving it as-is, and it makes testing easier/possible.
Back to RTBC for further consideration.
Thanks,
-Derek
Comment #41
larowlanfor posterity, here is the mock in tests
Comment #42
alexpottAdding issue credit.
Comment #43
alexpottCommitted 55c96a6 and pushed to 8.7.x. Thanks!
Comment #45
Wim LeersThis triggered failures in JSON:API due to new deprecation errors. Fixing at #3036772: Drupal core compatibility: file_upload_max_size() deprecated in Drupal >= 8.7.
Nice work here!
Comment #47
volegerMissed the last call in the run-tests.sh
See #3092268: Replace call of deprecated drupal_set_time_limit() function
Comment #48
kim.pepperPublished change record.