Allow `uploads:missing` Rake task to be run for a single site.

This commit is contained in:
Guo Xiang Tan 2016-09-02 10:22:03 +08:00
parent 0a39ba43ed
commit 82324db71a
1 changed files with 40 additions and 37 deletions

View File

@ -318,50 +318,53 @@ end
# list all missing uploads and optimized images
task "uploads:missing" => :environment do
if ENV["RAILS_DB"]
list_missing_uploads
else
RailsMultisite::ConnectionManagement.each_connection do |db|
list_missing_uploads
end
end
end
def list_missing_uploads
if Discourse.store.external?
puts "This task only works for internal storages."
return
end
public_directory = "#{Rails.root}/public"
RailsMultisite::ConnectionManagement.each_connection do |db|
Upload.find_each do |upload|
if Discourse.store.external?
puts "This task only works for internal storages."
next
# could be a remote image
next unless upload.url =~ /^\/[^\/]/
path = "#{public_directory}#{upload.url}"
bad = true
begin
bad = false if File.size(path) != 0
rescue
# something is messed up
end
Upload.find_each do |upload|
# could be a remote image
next unless upload.url =~ /^\/[^\/]/
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.find_each do |optimized_image|
# remote?
next unless optimized_image.url =~ /^\/[^\/]/
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
puts path if bad
end
OptimizedImage.find_each do |optimized_image|
# remote?
next unless optimized_image.url =~ /^\/[^\/]/
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
################################################################################