Rake task to clean up broken screenshots works now

This commit is contained in:
Christoph Haas 2016-08-17 09:27:50 +02:00
parent 1a49fc2777
commit 046897f1c6

View file

@ -6,18 +6,16 @@ namespace :debshots do
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
path = screenshot.image.path(:large)
# Rails.logger.info "- #{screenshot.id} (package: #{screenshot.package.name}) (path: #{path})"
unless path and (File.file? path)
Rails.logger.info "Screenshot #{screenshot.id} image file not found at path '#{path}'. Removing."
screenshot.delete
end
end
Rails.logger.info "Done."
end
end