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.
In my case, i have images in private folder, without a record in the file_managed table.
When i try to generate derivative images via image_style_ hooks, i found this error:
Notice: Trying to get property of non-object in webform_multifile_file_download() (line 79 of ...)
Problem is that $target_document is not set.
Here is the patch:
diff --git a/modules/contrib/webform_multifile/webform_multifile.module b/modules/contrib/webform_multifile/webform_multifile.module
index ef0c5b1..0a6ee1d 100644
--- a/modules/contrib/webform_multifile/webform_multifile.module
+++ b/modules/contrib/webform_multifile/webform_multifile.module
@@ -76,7 +76,7 @@ function webform_multifile_file_download($uri) {
$submission_id = $submission_uid = NULL;
while($multifile_row = $multifile_scan->fetchAssoc()) {
$file_ids = unserialize($multifile_row['data']);
- if (in_array($target_document->fid, $file_ids) ) {
+ if ($target_document && in_array($target_document->fid, $file_ids) ) {
$submission_id = $multifile_row['sid'];
}
}
@@ -94,7 +94,7 @@ function webform_multifile_file_download($uri) {
return -1;
}
// This is not a webform-controlled file.
- return NULL;
+ return null;
}
/**
Comment | File | Size | Author |
---|---|---|---|
#29 | interdiff-2175623-25-29.txt | 813 bytes | fjgarlin |
#29 | webform_multifile-file_usage-2175623-29.patch | 8.5 KB | fjgarlin |
Comments
Comment #1
richsky CreditAttribution: richsky commentedOh my... I also found this was a serious issue when unserialize($multifile_row['data']) is executed against Null or not serialized data.
I added this test:
Comment #2
sammys CreditAttribution: sammys commentedHere's a patch that should handle both situations more gracefully.
Comment #3
Shuairan CreditAttribution: Shuairan commentedThanks for the patch!
BTW, the whole webform_multifile_file_download() function is big crap. Really big crap.
With ~10 private images on a page and around ~20.000 webform submissions this two stupid notices producing around 250.000 watchdog entries per request here.
Even with the patch this code loops over all webform submissions (with a multifile field) for each download request, in most cases just to find out it is NOT responsible for the file. BTW, that's why I call that piece of code "big crap".
So if you are building a huge site with downloadable private files and lots of webform submissions, be aware of that!
I think I'll have to write a patch to restructure the logic behind this by using the file_usage table...
Comment #4
ahsanra CreditAttribution: ahsanra commentedSo is there any solution to those damn 10,000 loops and watchdog entries being produced by just visiting the gallery page? I am having the same problem and it is very annoying to have those entries in your watchdog list.
Anyone come up with solution? I have applied both the patches but still it produces those watchdog entries with something like
Warning: in_array() expects parameter 2 to be array, boolean given in webform_multifile_file_download() (line 80 of /docroot/sites/all/modules/contrib/webform_multifile/webform_multifile.module).
Whats the solution?
Comment #5
Shuairan CreditAttribution: Shuairan commentedHere is a patch which might help you, depending on which webform version you are using.
The patch adds a webform_multifile_webform_submission_presave() function which is very similar to webform-4.1's webform_submission_presave function. It adds the multifile files to the file_usage table. Be careful: Might not work if you are using "file" and "multifile" form fields together (in one single form)!
This way the webform file access handled by webform_file_download() in the main module works quite well for me.
And it also removes the broken webform_multifile_file_download function.
Comment #6
Jochen Wendebaum CreditAttribution: Jochen Wendebaum commentedWhat is the status of this patch? Will it be included into the projet some day?
Comment #7
laboratory.mikeThe initial patch works. Which patch do we want to review & commit?
Comment #8
laboratory.mikeComment #9
JeroenTPatch in #5 worked for me, but the patch no longer applied and I got a notice on node/.../done.
Patch attached is a re-roll of patch #5 + a small bugfix.
Comment #10
JeroenTUploaded the wrong patch. This is the right one.
Comment #11
brianfisher CreditAttribution: brianfisher at Chapter Three commentedwith webform 3.24 patch fails to upload file, generates log entries
Looking at hook_webform_submission_presave()
but the patch includes
Comment #12
brianfisher CreditAttribution: brianfisher at Chapter Three commentedrevised patch to detect api version
Comment #13
brianfisher CreditAttribution: brianfisher at Chapter Three commentedreroll patch
Comment #14
GaëlGWarning, since last security update, unserialize has to be replaced with drupal_json_decode in patch #13.
Comment #15
marco-sI've updated the patch with 'drupal_json_decode' (instead of 'unserialize').
This patch solves this issue as well: 2821896
Comment #16
joewhitsittI don't think the presave works if the multifile component exists but isn't populated. Testing #15 patch
I get $submission->data[1][0] = NULL which causes errors:
This also causes issues when there is more than one multifile type component on a form and one of them is not populated. The errors above occur but the files that were uploaded via the other component get a usage 0 and aren't accessible. access denied.
Comment #17
Jānis Bebrītis CreditAttribution: Jānis Bebrītis at Wunder commentedHere's a patch to fix two issues:
- array_merge does not like false value that get returned by empty parameter in drupal_json_decode
- files cannot be deleted because the deleting code is targeted for webform3
Comment #18
rudins CreditAttribution: rudins at Wunder commentedThere is correct patch, small fix ;)
Comment #19
nicobot CreditAttribution: nicobot at Front ID commentedI tested the latest patch with current dev and it works fine.
Thanks!
Comment #20
nicobot CreditAttribution: nicobot at Front ID commentedMoving to RBTW, patch works fine.
Comment #21
Jaesin CreditAttribution: Jaesin at Chapter Three commentedPlus 1 for this patch.
Comment #22
marco-sPatch #18 works. Thanks.
Comment #23
VISIOS CreditAttribution: VISIOS commentedPatch #18 works for me too. Unfortunately took me 2 hours to find out Webform Multiple File Upload caused this. Please commit, thanks.
Comment #24
dmsmidtThanks for the work on this. Some comments.
This can't be committed like this. It should be tested or there should be an incompatibility validation during the setup of the form.
Either way, we should fix typ0's and coding standards.
This will only work if this hook runs later than webform_webform_submission_presave(). Check if safer if we check the existence of the keys as well.
We can reduce nesting here with early continues.
Let's just check for version higher than 3. And add an helper function for getting the major version.
Use early return.
Early continue.
Reuse version check helper function.
Fix coding standards.
Comment #25
dmsmidtHere is a new patch which fixes my mentioned issues. It also works with multiple components and together with the normal single File component.
Comment #26
swhitters CreditAttribution: swhitters as a volunteer commentedOh my gosh, I've been trying to fix this for ages. The patch in #25 works for me. Thank you.
Comment #27
jacob.embree CreditAttribution: jacob.embree at St. Louis Integration commentedNice going, dmsmidt. #25 looks good and fixes the access issues I was having.
Notes for anyone else wanting to use this patch:
webform_multiple_get_webform_major_version()
will assume an old version which will break stuff for Webform 7.x-4.x.Comment #28
ShaneOnABike CreditAttribution: ShaneOnABike at Bees on a Bike commentedIt's not clear to me whether this is related, but in my situation we had set multifiles to be uploaded to a private directory. I cannot download these files and keep getting Access Denied. I tried to apply the patch, and finally had to do that by hand to make it apply not sure why git was unhappy with it.
I noticed that the patch removes the download mechanism, and I //assume// it's using the default webform but I cannot be sure. How are files being downloaded now? Regardless, it still isn't working properly in my case. In using a single file upload all is fine so it's not a permissions issue on teh file structure itself.
What am I missing?
Comment #29
fjgarlin CreditAttribution: fjgarlin as a volunteer and at Amazee Labs commentedThanks a lot for the patch. I run into the issue described in #27 and made this addition to try to get the major version in another way if the previous attempts don't work (I am using git submodules).
Comment #30
jacob.embree CreditAttribution: jacob.embree at St. Louis Integration commented