Added rake task to remove orphaned screenshot records
This commit is contained in:
parent
3b056a2db8
commit
806a7cbcee
1 changed files with 23 additions and 0 deletions
23
lib/tasks/remove_broken_screenshots.rake
Normal file
23
lib/tasks/remove_broken_screenshots.rake
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue