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.
Replace deprecated drupal_unlink()
function calls with unlink()
method of the file_system
service.
Comment | File | Size | Author |
---|---|---|---|
#66 | interdiff-3021434-65-66.txt | 801 bytes | voleger |
#66 | 3021434-66.patch | 21.95 KB | voleger |
Comments
Comment #2
volegerComment #3
volegerAdded legacy test.
Comment #5
volegerComment #6
volegerComment #8
volegerInteresting. Check if this will decrease ServiceCircularReferenceExceptions
Comment #9
volegerLooks like is more related to FileStorage of Config functionality. Let's see.
Comment #10
BerdirTests don't need injection IMHO, I think they can just use \Drupal::service() directly, maybe with a local variable if there are repeated calls in the same method.
Comment #11
volegerThanks, @Berdir! Applied changes.
Also tried the same way in FileStorage to avoid circular dependency reference.
Comment #13
andypostLooks streams are serialized somehow, attempt to fix it
Comment #15
volegerPostponed on #2244513: Move the unmanaged file APIs to the file_system service (file.inc)
Comment #16
BerdirThat is in, but this needs a reroll now.
Comment #17
BerdirReroll was trivial, just one conflict in file.inc for a change that is no longer necessary.
Comment #18
BerdirI would leave this snippet out of this issue and instead postpone on #2940135: Use file_system service to \Drupal\Core\Config\FileStorage, possibly only after it passes.
Looks like FileTransfer comes with a factory method that we can use to "inject", similar to controllers/forms. It doesn't have $container, but we can then still make $fileSystem a real injected dependency.
Also, maybe add DependencySerializationTrait to this class, that might help with those weird test fails?
Id' also add .. service here, it doesn't return the actual "file system". That only works with things like manager/handler or so in the class/service name.
lets do the NULL/@trigger_error() dance here.
\Drupal::service(), same with some other tests.
we can put this in \Drupal\KernelTests\Core\File\FileSystemDeprecationTest now.
Comment #19
volegerJust reroll after #3026588: Move ArchiveTar to composer
Comment #20
volegerAddressed #18
Comment #21
volegerAnd postponing on #2940135: Use file_system service to \Drupal\Core\Config\FileStorage
Comment #22
volegerI mean postponed status
Comment #23
voleger@Berdir you're right. #10.2 had resolved that errors, so deprecation messages that left in #20 should gone when #2940135: Use file_system service to \Drupal\Core\Config\FileStorage would be in.
Comment #24
BerdirComment #25
volegerJust reroll
Comment #26
volegerComment #27
volegerComment #28
Peter MajmeskuComment #29
Berdirlets make this private, like in FileStorage.
the deprecation message needs to be updated to say deprecated in 8.0.0 (I think?) and will be removed before 9.0.0
Comment #30
Peter MajmeskuSet the visibility in LocalStream:: getFileSystem() to private.
Regarding the deprecation message. From what I see: there is already one. Could you please specify more detailed where it's missing?
Comment #32
BerdirThe message needs to include the information that I mentioned. Here's a full example from format_date():
Also looks like we still have 2 failing tests.
Comment #34
Peter MajmeskuThe failing tests are weird. In Jenkings are several classes mentioned. Like FileTransferAuthorizeFormTest. However, all tests seem to be ok. How can I see in Jenkins, which test is actually failing?
FileTransferAuthorizeFormTest is failing on my machine. Other tests are running. I am using Chromedriver. Do I miss something in my phpunit.xml settings?
Comment #35
Peter MajmeskuComment #36
Peter MajmeskuUpdated PHPDoc block for @deprecated tag. Added interdiff file.
Comment #37
BerdirThis is the place where you need to update the deprecation message. You only touched the test that asserts that it is printed.
Also the @deprecated above.
In the test then you have the identical string and only @expectedDeprecation.
Comment #38
Peter MajmeskuMoved the deprecation message to drupal_unlink(). Left only @expectedDeprecation and the already existing comment in testUnlink().
Comment #39
BerdirThe trigger error is not updated yet, both messages need to be basically identical.
Comment #40
Peter Majmesku@Berdir: I do not get you. Could you please express your remark more precisely? See details below.
Identical with contents of @expectedDeprecation annotation in FileSystemDeprecationTest::testDeprecatedDrupalTempnam(). __FUNCTION__ will pass the function name.
@expectedDeprecation annotation text is Identical with @trigger_error() parameter in drupal_chmod().
Do you want me to change the @trigger_error() function parameter in the constructor of Drupal\Core\FileTransfer\Local?
Comment #41
BerdirI don't know how else to explain it, look at the date_format() example in #32 and updated examples in file.inc that have @trigger_error(). @deprecated and @trigger_error() and @expectedDeprecation *all* need to have the same structure that includes the version.
Comment #42
Peter MajmeskuI have edited the patch. The assertion checks now the concatenated text from drupal_unlink() annotation tags.
Comment #43
BerdirSome last nitpicks, then I think we are done here.
If you're looking for other things to work on, I had a look at file.inc and it looks like #3021450: Add @trigger_error to deprecated functions in file.inc and replace their usages missed to add a @trigger_error() to drupal_realpath() and file_directory_os_temp(). Others are already covered in other issues like #3034072: Move file uri/scheme functions from file.inc and FileSystem to StreamWrapperManager. there's also file_directory_temp(), not sure what do with that. We can't have FileSystem depend on configuration. This is the same problem as the one I wrote about in the stream wrapper manager issue above in regards to file_default_scheme().
Hm, the change to \Drupal::service() instead of just the classname is different compared to all other functions that we've been deprecated. Lets undo that and keep it like it was before, with ..FileSystem::unlink() in all places.
This should be "8.7.0" instead of "8.7.x"
same here.
Comment #44
BerdirFound #931794: 'file_temporary_path' variable and file_directory_temp() function should match in regards to the temp function.
Comment #45
volegerAddressed #43
Comment #46
Peter MajmeskuLast patch solves the remaining.
Comment #47
Peter MajmeskuWould you please review #3038513: Replace drupal_valid_test_ua() with static method for Drupal 9?
Comment #48
Berdirbeta is the deadline for deprecations, at least simple stuff like constructors: https://drupal.slack.com/archives/CDDD98AMN/p1552125380214700.
So we can keep 8.7.0 for now.
Comment #49
BerdirComment #50
volegerNice! here the patch
Comment #51
BerdirThanks, looks good now.
Comment #52
volegerbump
Comment #53
larowlanDid we give thought to changing the signature of the factory too, to include passing the file system? As I can see there is only one call in core for it - \Drupal\Core\FileTransfer\Form\FileTransferAuthorizeForm::getFiletransfer
We could do the same thing here, make it optional, trigger_error etc?
Then we could actually do DI in \Drupal\Core\FileTransfer\Form\FileTransferAuthorizeForm::getFiletransfer
The file system has a dependency on the stream wrapper manager, and this then makes the wrappers depend on it, which is a pseudo-circular dependency. How about a follow-up where we explore extending stream wrapper and stream wrapper manager interfaces to support add a setFileSystem method, which FileSystem could call in its constructor
Comment #54
Berdir1. I'd try to keep this minimal. There's an issue to use a more modern approach for discovery of those classes, I guess plugins, and then they would be able to use the standard plugin create method.
2. We can try to improve it in a follow-up, yeah. This dependency already exists, the only thing we do is remove one level of indirection. We did basically the same in #2940135: Use file_system service to \Drupal\Core\Config\FileStorage.
Comment #55
volegerSo, based on #54, back to rtbc
Comment #56
volegerrerolled
fixed version in the deprecation messages
Comment #57
volegerComment #59
kim.pepperStill need to create the follow up issue?
Comment #60
andypostI bet yes, cos injection of file system is pita every service
Comment #61
kim.pepperIf the file system is a real dependency, then I don't think injecting it is an issue. The real problem is the circular dependencies that have most likely alway been there, that are now being exposed by dependency injection.
We're trying to untangle the mess.
Comment #62
BerdirI created the following two issues, would be nice to get this in, I don't think it makes sense to improve the patch as it is now:
#3048126: Make it easier to inject the FileSystem service
#3048120: Improve dependency injection for FileTransfer classes
Comment #63
volegerLink the issues
Comment #65
kim.pepperRe-roll
Comment #66
volegerLooks good.
Just found one missed replacement in the comments.
Comment #68
larowlanCommitted 870b564 and pushed to 8.8.x. Thanks!