Closed (fixed)
Project:
Drupal core
Version:
11.x-dev
Component:
file system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
12 Jul 2021 at 07:34 UTC
Updated:
7 Jul 2023 at 00:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
kim.pepperInitial patch. I've split FileFetcher into two separate classes: unmanaged in core namespace, and managed in the file module.
Comment #3
kim.pepperAdds @group annotation and CR link.
Comment #5
kim.pepperFix test fails.
Comment #6
berdirI'm unsure if we really want to support destination being optional.
This puts files in the root public:// folder, which I think is a bad practice. You should at least bother to create a directory for your module somewhere. It's also the only case we use the default scheme, so if we require destination, we could drop that.
There are no non-test calls in core that don't pass a destination and I also can't see any examples on the first page of http://grep.xnddx.ru/search?text=system_retrieve_file.
I'd vote to drop that feature.
I've been wondering about this line before, why it's specifically in this function and nowhere else. Tracked it down to #573300: system_retrieve_file() fails in file_unmanaged_copy() (invocation with path instead of URI), which was 11 years ago, but can't see the reason it was added.
I do like that Dries already pointed this out back then:
> I find it odd that an API function uses drupal_set_message() but that is probably best left for another issue.
11 years later, we finally have that issue ;)
what's the reason for wrapping fileSystem->saveData()? Seems like that requires to copy a lot of documentation for a single line of code?
Ah, that's why.
Wondering something similar as with the empty destination. How often is this used and is there a better way.
Having two services do something different with the same interface does seem a bit unusual too. And the interface forces a string return, but file_save_data() would return an entity, is that code path untested now?
the deduplication logic in file_save_data() is definitely useful. Maybe the replacement should just be about creating a file entity from an already existing local file? then we only need one service, you can use retrieve file and create the file entity yourself with a single extra call.
FWIW, not sure if there's much left here that's actually worth putting in a service then, with no error handling, you do need to duplicate that then.
Comment #7
kim.pepperThanks for the review. I've also started on #3223209: deprecate file_save_data, file_copy and file_move and replace with a service which might make more sense to do before this one? Feels like a big ball of string. :-)
Comment #8
daffie commentedI get why the services are named:
file.fetcher.unmanagedandfile.fetcher.managed. Only I am not happy with the new core service name. The first part "file." implies that it is part of the file module. Only it is not. It is part of core. My second objection is the ".unmanaged" part. The class name is FileFetcher, not FileFetcherUnmanaged. Or the class name is not correct.Missing the part that the parameter is optional and what its default value is.
Missing the part that the parameter is optional and what its default value is.
Out of scope change.
Should it not be "@return string|false"
The method saveData() can return false, therfor the method fetch can also return false.
Can we change the name to FileFetcherManaged.
Comment #9
andypostComment #10
anweshasinha commentedI have worked in this issue and I am submitting my patch. Please review it.
Comment #11
daffie commentedPatch is failing testbot.
Comment #12
hmendes commentedAdding a patch from #10 fixing the phpcs errors reported.
Comment #14
berdirAgree with postponing on #3223209: deprecate file_save_data, file_copy and file_move and replace with a service, we should work bottom up here.
Also, the last two patches seem to just move the function around, something went wrong there. Ignore those.
Comment #15
andypost+1 to postpone, meantime the fetcher service is http(s):// stream it just need to read data
Comment #16
kim.pepperI'm actually thinking this should be deprecated without replacement. It's literally just
or
$file_system->saveData($data, $path, $replace)depending on managed or not.
Comment #20
kim.pepperThe issue this was postponed on was committed in Drupal 9.3.x.
Comment #21
andypostneeds re-roll
Comment #22
kim.pepperAs mentioned in #16 I think we should deprecate without replacement.
I can only see 2 places in core where this gets used, and both of them just need to use the unmanaged file system to write the file.
Comment #23
kim.pepperFormat deprecation message correctly.
Comment #25
kim.pepperlocale_translation_download_sourceexpects the file to be saved with the same name as the fetched URL file.Comment #26
berdirDo we need to take care of error handling in these replacements? system_retrieve_file() converted any exceptions to messages.
Comment #27
kim.pepperThere is #2177545: Change system_retrieve_file function to return error instead of generating Drupal messages linked in the IS. Do we want to document them, and just let the exceptions bubble up? Personally, I think it's strange to set messages at this level.
Comment #28
berdirSure, just messages is strange, but not catching them means we'll break update and translation import processes, I've definitely seen error messages around translation imports in the past. As an Api function, adding messages was weird, but in this specific cases, that might be fine?
Comment #29
berdirAnd #2177545: Change system_retrieve_file function to return error instead of generating Drupal messages will be a won't fix once the function is deprecated but would result in exactly the same as we have to do here. Returning an error means callers need to make the decision on how to handle the error, just like here.
Comment #30
kim.pepper> Returning an error means callers need to make the decision on how to handle the error, just like here.
But it should be handled further up that call stack. That's where you can potentially do something more useful with more context.
Comment #31
kim.pepperCopied over setting messages if exceptions are caught in the two locations where this function has been replaced.
Updated the title and IS to reflect the current solution.
Comment #32
smustgrave commentedCan we add test coverage for the new errors being logged here?
Comment #33
kim.pepperThese are not new errors being logged. We're copying the behaviour of
system_retrieve_file()which is now deprecated.Comment #34
smustgrave commentedAh in that case think this is good to go then!
Comment #36
smustgrave commentedrandom
Comment #37
larowlanAre we sure the test fail here is random .. its to do with a locale file it seems?
Comment #38
larowlanRe queued tests
Comment #39
kim.pepperComment #40
kim.pepperRebase on 11.x and updated deprecation message with 10.2.0 version.
Comment #41
jibranI reviewed the patch with @kim.pepper at DrupalSouth the changes look good so setting it back to RTBC.
Comment #42
larowlanNo longer applies, can we get a reroll please 🙏
Comment #43
smustgrave commentedJust a reroll.
Comment #44
larowlanIssue credit
Comment #46
larowlanCommitted 8219cb1 and pushed to 11.x. Thanks!
Published the change record