Rake task to clean up broken screenshots works now
This commit is contained in:
parent
1a49fc2777
commit
046897f1c6
1 changed files with 6 additions and 8 deletions
|
|
@ -6,18 +6,16 @@ namespace :debshots do
|
||||||
Rails.logger.level = Logger::INFO
|
Rails.logger.level = Logger::INFO
|
||||||
#Rails.logger.level = Logger::DEBUG
|
#Rails.logger.level = Logger::DEBUG
|
||||||
|
|
||||||
base_path = Rails.root.join('public')
|
|
||||||
|
|
||||||
Rails.logger.info "Iterating over screenshots"
|
Rails.logger.info "Iterating over screenshots"
|
||||||
Screenshot.all.each do |screenshot|
|
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
|
# Check that the file actually exists
|
||||||
unless File.file? path
|
path = screenshot.image.path(:large)
|
||||||
Rails.logger.error "Screenshots not found at #{path}. Removing."
|
# Rails.logger.info "- #{screenshot.id} (package: #{screenshot.package.name}) (path: #{path})"
|
||||||
next
|
unless path and (File.file? path)
|
||||||
|
Rails.logger.info "Screenshot #{screenshot.id} image file not found at path '#{path}'. Removing."
|
||||||
|
screenshot.delete
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Rails.logger.info "Done."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue