mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
Allow uploads:missing
Rake task to be run for a single site.
This commit is contained in:
@ -318,50 +318,53 @@ end
|
|||||||
|
|
||||||
# list all missing uploads and optimized images
|
# list all missing uploads and optimized images
|
||||||
task "uploads:missing" => :environment do
|
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"
|
public_directory = "#{Rails.root}/public"
|
||||||
|
|
||||||
RailsMultisite::ConnectionManagement.each_connection do |db|
|
Upload.find_each do |upload|
|
||||||
|
|
||||||
if Discourse.store.external?
|
# could be a remote image
|
||||||
puts "This task only works for internal storages."
|
next unless upload.url =~ /^\/[^\/]/
|
||||||
next
|
|
||||||
|
path = "#{public_directory}#{upload.url}"
|
||||||
|
bad = true
|
||||||
|
begin
|
||||||
|
bad = false if File.size(path) != 0
|
||||||
|
rescue
|
||||||
|
# something is messed up
|
||||||
end
|
end
|
||||||
|
puts path if bad
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
Reference in New Issue
Block a user