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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz’s picture

There'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.

bojanz’s picture

Status: Active » Needs work
FileSize
1.4 KB

Here'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.

gusaus’s picture

Appreciate 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.

bojanz’s picture

If 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.

bojanz’s picture

Title: Download archive of selected audio files? » Download archive of selected files?

Tweak title.

joemoraca’s picture

I 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 ....

joemoraca’s picture

line 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?

bojanz’s picture

Maybe you've checked the "Force single" option in the VBO field options?

joemoraca’s picture

embarrassing .... 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

joemoraca’s picture

this code (snippet from patch in #2) gets the correct file urls from the checked files in the file list

 foreach ($files as $file) {
  //  $zip->addFile(file_build_uri($file->filepath), $file->filename);
    $myfile = file_create_url($file->uri);
    $zip->addFile($myfile);

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.

joemoraca’s picture

Status: Needs work » Needs review

Good News...
I figured out ZipArchive doesn't want a url it wants a path so

    $zip->addFile(drupal_realpath($file->uri),$file->filename);

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

gusaus’s picture

Just trying to grasp what needs reviewing - the patch?

bojanz’s picture

There'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.

gusaus’s picture

Appreciate your work on this bojanz! Hopefully this could be a component for #1223882: Playlists and we'll be able to help further development.

chrowe’s picture

Ok, 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.

bojanz’s picture

Thanks, 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.

landing’s picture

sub

bojanz’s picture

FileSize
13.21 KB

Here'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.

bojanz’s picture

Title: Download archive of selected files? » Provide an action for creating an archive of selected files
Status: Needs review » Fixed

Committed 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

NonProfit’s picture

Hi, I used the patch from #19 (thanks, BTW) on top of VBO 7.x-3.x-dev and received the errors:

    Notice: Undefined variable: destination in views_bulk_operations_archive_action() (line 64 of [snip]/sites/all/modules/views_bulk_operations/actions/archive.action.inc).
    Notice: Undefined variable: destination in views_bulk_operations_archive_action() (line 65 of [snip]/sites/all/modules/views_bulk_operations/actions/archive.action.inc).
    Notice: Undefined variable: destination in views_bulk_operations_archive_action() (line 66 of [snip]/sites/all/modules/views_bulk_operations/actions/archive.action.inc).
    PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO {file_managed} (uid, filename, uri, filemime, filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => [:db_insert_placeholder_3] => application/octet-stream [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 1317882498 ) in drupal_write_record() (line 6868 of [snip]/includes/common.inc).

Any insight appreciated, thanks!

bojanz’s picture

The 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.

NonProfit’s picture

Perfect, thanks a million bojanz!

kenorb’s picture

NonProfit’s picture

kenorb, thanks for the info, but in my case bojanz called it correctly in #22.

Orangefox Web Developers’s picture

Issue summary: View changes

Cant 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

retiredpro’s picture

I 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