Sha256: ddc8410ebd834b9ce8e48880d6680c72c7d03116433b486c8771778e5926d2bb

Contents?: true

Size: 561 Bytes

Versions: 10

Compression:

Stored size: 561 Bytes

Contents

namespace :sufia do

  desc "Reports on and optionally removes empty batches that contain no associated files"
  task :empty_batches, [:remove] => :environment do |t, args|
    option = args.to_hash.fetch(:remove, "keep")
    Batch.all.each do |batch|
      if batch.generic_files.empty?
        print "#{batch.id} contains no files - "
        if option == "remove"
          batch.destroy
          puts "deleted"
        else
          puts "to delete, rerun with the remove option: rake sufia:empty_batches[remove]"
        end
      end
    end
  end

end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
sufia-models-6.7.0 lib/tasks/batch_cleanup.rake
sufia-models-6.6.1 lib/tasks/batch_cleanup.rake
sufia-models-6.6.0 lib/tasks/batch_cleanup.rake
sufia-models-6.5.0 lib/tasks/batch_cleanup.rake
sufia-models-6.4.0 lib/tasks/batch_cleanup.rake
sufia-models-6.3.0 lib/tasks/batch_cleanup.rake
sufia-models-6.2.0 lib/tasks/batch_cleanup.rake
sufia-models-6.1.0 lib/tasks/batch_cleanup.rake
sufia-models-6.0.0 lib/tasks/batch_cleanup.rake
sufia-6.0.0 sufia-models/lib/tasks/batch_cleanup.rake