This is a backport of: https://www.drupal.org/project/drupal/issues/3016814
-------------------------
Original text:
-------------------------
I have a implementation of hook_file_download because I check if this is a private/specific file and do a redirection for specific link:
function my_file_download($uri) {
//some code here
// if(substr($uri,0,26) =='private://specificcontent/'){
header("location:http://mysite.com/myURL");
}But, when I remove a file using user interface, this function too is called, generating a error, because the code try redirect for "http://mysite.com/myURL". I believe that when the file is deleted, not is correct receive a call in hook_file_download. But, case if it is not evitable, what I need do for verify that is a delete command and ignore redirection command?
There is a useful solution for version 8, but I haven't found the same solution for version 7 of drupal:
Issue fork drupal-3212823
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
avpadernoComment #3
poker10 commentedThanks for reporting this. I do not see any patch, so it seems like Active is the correct status (there is nothing to review).
Comment #5
poker10 commentedI have backported the change from #3016814: Don't trigger hook_file_download when no file is requested together with test changes.
Regular pipeline is green: https://git.drupalcode.org/project/drupal/-/pipelines/148353
Test only job is failing here: https://git.drupalcode.org/project/drupal/-/jobs/1343442
Moving to Needs review.
Comment #6
poker10 commentedComment #7
poker10 commentedAdding the tag for the final review.
Comment #8
mcdruid commentedThis looks pretty good but I'm not sure about the assertions that reference an element on the return value of
variable_get()- e.g.:Perhaps it's safe to assume that the variable will always be set and that element will be present, but if we do something similar in isolation:
It may make the code more long-winded but can we avoid this?
Comment #9
poker10 commentedYes, I was on the edge when backporting these rows. Seems like we can use
file_test_get_all_calls()to retrieve these results too, so I have updated the MR with this change. Hopefully now it is cleaner and safer. Thanks!Tests are still green: https://git.drupalcode.org/project/drupal/-/pipelines/187591
And test-only job is still failing: https://git.drupalcode.org/project/drupal/-/jobs/1743067
Comment #11
mcdruid commentedThanks - it's a bit circuitous but I think better to avoid potentially(/theoretically) referencing non-existent elements.