From 996ab1ae1752551bb1a330df73fea287c28edcef Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 11 May 2015 10:30:22 +1000 Subject: [PATCH] FEATURE: task to find all missing local images --- lib/tasks/uploads.rake | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake index f8b8c25b9cc..86c50f41b02 100644 --- a/lib/tasks/uploads.rake +++ b/lib/tasks/uploads.rake @@ -157,3 +157,52 @@ task "uploads:clean_up" => :environment do end end + + +# list all missing uploads and optimized images +task "uploads:missing" => :environment do + + public_directory = "#{Rails.root}/public" + + RailsMultisite::ConnectionManagement.each_connection do |db| + + if Discourse.store.external? + puts "This task only works for internal storages." + next + end + + + Upload.order(:id).find_each do |upload| + + # could be a remote image + next unless upload.url =~ /^\/uploads\// + + path = "#{public_directory}#{upload.url}" + bad = true + begin + bad = false if File.size(path) != 0 + rescue + # something is messed up + end + puts path if bad + end + + OptimizedImage.order(:id).find_each do |optimized_image| + + # remote? + next unless optimized_image.url =~ /^\/uploads\// + + path = "#{public_directory}#{optimized_image.url}" + + bad = true + begin + bad = false if File.size(path) != 0 + rescue + # something is messed up + end + puts path if bad + end + + end + +end