lib/tasks/paperclip.rake in kt-paperclip-4.4.0 vs lib/tasks/paperclip.rake in kt-paperclip-5.4.0

- old
+ new

@@ -16,11 +16,11 @@ if attachment_names.empty? raise "Class #{klass.name} has no attachments specified" end - if !name.blank? && attachment_names.map(&:to_s).include?(name.to_s) + if name.present? && attachment_names.map(&:to_s).include?(name.to_s) [ name ] else attachment_names end end @@ -44,11 +44,11 @@ names.each do |name| Paperclip.each_instance_with_attachment(klass, name) do |instance| attachment = instance.send(name) begin attachment.reprocess!(*styles) - rescue Exception => e + rescue StandardError => e Paperclip::Task.log_error("exception while processing #{klass} ID #{instance.id}:") Paperclip::Task.log_error(" " + e.message + "\n") end unless instance.errors.blank? Paperclip::Task.log_error("errors while processing #{klass} ID #{instance.id}:") @@ -62,11 +62,12 @@ task :metadata => :environment do klass = Paperclip::Task.obtain_class names = Paperclip::Task.obtain_attachments(klass) names.each do |name| Paperclip.each_instance_with_attachment(klass, name) do |instance| - if file = Paperclip.io_adapters.for(instance.send(name)) + attachment = instance.send(name) + if file = Paperclip.io_adapters.for(attachment, attachment.options[:adapter_options]) instance.send("#{name}_file_name=", instance.send("#{name}_file_name").strip) instance.send("#{name}_content_type=", file.content_type.to_s.strip) instance.send("#{name}_file_size=", file.size) if instance.respond_to?("#{name}_file_size") instance.save(:validate => false) else @@ -88,10 +89,23 @@ Rake::Task['paperclip:refresh:thumbnails'].execute end end Paperclip.save_current_attachments_styles! end + + desc "Regenerates fingerprints for a given CLASS (and optional ATTACHMENT). Useful when changing digest." + task :fingerprints => :environment do + klass = Paperclip::Task.obtain_class + names = Paperclip::Task.obtain_attachments(klass) + names.each do |name| + Paperclip.each_instance_with_attachment(klass, name) do |instance| + attachment = instance.send(name) + attachment.assign(attachment) + instance.save(:validate => false) + end + end + end end desc "Cleans out invalid attachments. Useful after you've added new validations." task :clean => :environment do klass = Paperclip::Task.obtain_class @@ -107,10 +121,10 @@ end end end end - desc "find missing attachments. Useful to know which attachments are broken" + desc "find missing attachments. Useful to know which attachments are broken" task :find_broken_attachments => :environment do klass = Paperclip::Task.obtain_class names = Paperclip::Task.obtain_attachments(klass) names.each do |name| Paperclip.each_instance_with_attachment(klass, name) do |instance|