Added migration script to add screenshots to Paperclip

This commit is contained in:
Christoph Haas 2015-01-04 14:20:31 +01:00
parent f5d099e30a
commit 38df37057a

View file

@ -0,0 +1,32 @@
desc "Convert images from the original screenshots directory tree to paperclip-styled images"
task :screenshots_to_paperclip => :environment do
Rails.logger = Logger.new(STDOUT)
Rails.logger.level = Logger::INFO
#Rails.logger.level = Logger::DEBUG
base_path = Rails.root.join('public')
Rails.logger.info "Iterating over screenshots"
Screenshot.all.each do |screenshot|
path = File.join(base_path, screenshot.image_url(:large))
Rails.logger.info "- #{screenshot.id} (package: #{screenshot.package.name}) (path: #{path})"
# Check that the file actually exists
unless File.file? path
Rails.logger.error "Screenshots not found at #{path}. Skipping."
next
end
# Has the screenshot been migrated already?
if screenshot.image.exists?
Rails.logger.error "Screenshot already migrated. Skipping."
next
end
File.open(path, 'rb') do |image_file|
screenshot.image = image_file
screenshot.save
end
end
end