From abb1d1487ea35e6439c23f6004881c4805d4bd0a Mon Sep 17 00:00:00 2001 From: Alex Dolski Date: Tue, 5 Mar 2024 14:30:47 -0600 Subject: [PATCH] Add export_files --- lib/tasks/collections.rake | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/tasks/collections.rake b/lib/tasks/collections.rake index 55007249..8176cd51 100644 --- a/lib/tasks/collections.rake +++ b/lib/tasks/collections.rake @@ -2,6 +2,28 @@ require 'rake' namespace :collections do + desc "Export all files in a collection as a zip file" + task :export_files, [:collection_id, :dest_key] => :environment do |task, args| + collection = Collection.find(args[:collection_id]) + request_context = RequestContext.new(institution: collection.institution) + collection_ids = [collection.id] + collection.all_child_ids + + puts "Compiling a list of item IDs" + item_ids = [] + relation = Item.search.filter(Item::IndexFields::COLLECTIONS, collection_ids) + ItemPolicy::Scope.new(request_context, relation).resolve.each_id_in_batches do |result| + item_ids << result[:id] + end + + puts "Creating zip file" + Item.create_zip_file(item_ids: item_ids, + metadata_profile: collection.effective_metadata_profile, + dest_key: dest_key, + include_csv_file: false, + request_context: request_context, + print_progress: true) + end + desc "Reindex all collections" task reindex: :environment do # N.B.: orphaned documents are not deleted.