Added rake task to remove orphaned screenshot records

This commit is contained in:
Christoph Haas 2015-06-15 13:05:01 +02:00
parent 3b056a2db8
commit 806a7cbcee

View file

@ -0,0 +1,23 @@
namespace :debshots do
desc "Remove screenshot objects with non-existing images"
task :remove_broken_screenshots => :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.debug "- #{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}. Removing."
next
end
end
end
end