Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hi - Maybe I'm missing it, but I can't see the 'Download archive of selected files' action in the D7 release as described in this issue #731646: Can we have download file functionality?. Specifically we're trying to create a mechanism for downloadable audio playlists as described in (too much) detail here - http://groups.drupal.org/node/145189
Could VBO be one part of the solution?
Comment | File | Size | Author |
---|---|---|---|
#18 | archive.patch | 13.21 KB | bojanz |
#15 | archivedownloadaction-1222844-15.patch | 1.88 KB | chrowe |
#2 | archive.patch | 1.4 KB | bojanz |
Comments
Comment #1
bojanz CreditAttribution: bojanz commentedThere's such functionality in VBO D6 (archive.action.inc), you can port it to D7.
It's something I would like like to have in VBO D7, but it hasn't been a priority so far.
Comment #2
bojanz CreditAttribution: bojanz commentedHere's something you can use as a starting point. Not completely right (VBO stays on the confirmation page when the archive is downloaded, can't open the zip on my mac). And since it's using aggregation, it can't use Batch API, which mean it will choke on a large number of files (hundred, thousand, depends on your memory limit).
An ideal solution would just fill the (temporary) zip one file at a time, and after the action is done, give you a link for download.
Comment #3
gusaus CreditAttribution: gusaus commentedAppreciate that! I'll see how far I can get with your tips and will post back here. Definitely will be a useful feature. Thanks again.
Comment #4
bojanz CreditAttribution: bojanz commentedIf you disable the confirmation page for that specific action (setting in the VBO field settings in Views), that should remove the problem of getting stuck there.
And ignore the aggregation problem for now, I doubt you'll be packaging that many files for now.
Just make sure that the archive works.
Comment #5
bojanz CreditAttribution: bojanz commentedTweak title.
Comment #6
joemoraca CreditAttribution: joemoraca commentedI will be testing this soon as it is just what i am looking for.
Thanks for your work (all of you working on vbo)
edit: just tested patch. Only allows me to pick one file from list and zip archive was 0 file size so ....
Comment #7
joemoraca CreditAttribution: joemoraca commentedline 26
$zip->addFile(file_build_uri($file->filepath), $file->filename);
filepath doesn't exist so no files are getting loaded.
i can't figure out why it only allows me to select one file?
Comment #8
bojanz CreditAttribution: bojanz commentedMaybe you've checked the "Force single" option in the VBO field options?
Comment #9
joemoraca CreditAttribution: joemoraca commentedembarrassing .... yes that takes care of that ... I thought I had checked that.
unfortunately it still doesn't work due to the missing array value $file->filepath .... there is a $file->uri but that doesn't seem to work
Comment #10
joemoraca CreditAttribution: joemoraca commentedthis code (snippet from patch in #2) gets the correct file urls from the checked files in the file list
it also "seems" to add them to the zip file as the numFiles count in the zip variable gets incremented as it goes through the loop of files.
but the final downloaded file is zero bytes.
Comment #11
joemoraca CreditAttribution: joemoraca commentedGood News...
I figured out ZipArchive doesn't want a url it wants a path so
is all that needs to be changed from the patch in #2. This is now working for my needs.
FYI .. This version doesn't store the file path in the zip file (2nd parameter says use this as the stored name)
Thanks for a great start. Hope this helps
Comment #12
gusaus CreditAttribution: gusaus commentedJust trying to grasp what needs reviewing - the patch?
Comment #13
bojanz CreditAttribution: bojanz commentedThere's a patch in #2 that together with the fix from #11 seems to work as good as the 6.x version.
A version I'd commit needs to work like I described in #2, with aggregation off.
I plan to finish this in the next 7 days or so.
Comment #14
gusaus CreditAttribution: gusaus commentedAppreciate your work on this bojanz! Hopefully this could be a component for #1223882: Playlists and we'll be able to help further development.
Comment #15
chrowe CreditAttribution: chrowe commentedOk, I got this working, after getting the patch in the right place (may have been due to trying to use drush_patch_tools) and adding a reference to archive.action.inc in views_bulk_operations.module and remembering that I had to create a relationship to the files in the view before any actions that work with files will show up.
The attached patch is just #2 with the edit from #11 plus adding a reference to archive.action.inc in views_bulk_operations.module
It seems like D7 has a new core class in the API called ArchiverInterface http://api.drupal.org/api/drupal/includes--archiver.inc/interface/Archiv... which would seem to handle this. I am not a developer but I am trying to learn so I may see what I can do in this direction.
Comment #16
bojanz CreditAttribution: bojanz commentedThanks, I'll take it from here.
Wrote a version of the patch in #15 that uses Archiver, but ran into bugs (zip implementation doesn't act the same as the tar implementation) so I'm on the fence about the whole thing. Might be more trouble than it's worth.
Comment #17
landing CreditAttribution: landing commentedsub
Comment #18
bojanz CreditAttribution: bojanz commentedHere's a patch I would commit.
Test it and let me know what you think.
Supports an indefinite number of entities (no need for aggregate mode), supports adding files of the same name to the archive (gives them a different name like name_0.extension), works around a bunch of ZipArchive corner cases. Works through drush or any other way, since the archive is actually saved, and a link for download outputted to the user.
You can choose the scheme (private or public files, or some other local stream wrapper) and whether the file is temporary when configuring the operation, in the Views UI for the VBO field.
Tried doing it with core Archiver, but it was futile.
Also, this works for filefields / imagefields if you add a "File usage" relationship, then the "File: Bulk operations" field.
Comment #19
bojanz CreditAttribution: bojanz commentedCommitted a slightly improved version.
http://drupalcode.org/project/views_bulk_operations.git/commitdiff/7ea88...
Note that this also works for imagefields and filefields, if you add a "Files" relationship and then a "File: Bulk Operations" field.
Comment #21
NonProfit CreditAttribution: NonProfit commentedHi, I used the patch from #19 (thanks, BTW) on top of VBO 7.x-3.x-dev and received the errors:
Any insight appreciated, thanks!
Comment #22
bojanz CreditAttribution: bojanz commentedThe functionality is already present in 7.x-3.x-dev. No reason to apply any patch.
If the error persists with a new 7.x-3.x-dev install, open a new issue and we'll debug it.
Comment #23
NonProfit CreditAttribution: NonProfit commentedPerfect, thanks a million bojanz!
Comment #24
kenorb CreditAttribution: kenorb commented#21 error could be related to: #1163740: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 2: INSERT INTO {file_managed}
Comment #25
NonProfit CreditAttribution: NonProfit commentedkenorb, thanks for the info, but in my case bojanz called it correctly in #22.
Comment #26
Orangefox Web Developers CreditAttribution: Orangefox Web Developers commentedCant get this working, I have created a file view added file usage relation, then and added bulk operation file field, but there is no option to dowloand an archive, am i missing anything?
drupal 7 - vbo dev version
Comment #27
retiredpro CreditAttribution: retiredpro commentedI had the same issue as Orangefox Web Developers where the action did not show up. Installing PHP zip onto the server fixed it for me