better error handling for upload extension fixer

This commit is contained in:
Sam 2018-08-10 11:28:05 +10:00
parent 0451dba27a
commit 1fc2597626
2 changed files with 64 additions and 56 deletions

View File

@ -713,5 +713,5 @@ end
task "uploads:fix_incorrect_extensions" => :environment do
require_dependency "upload_fixer"
UploadFixer.fix_extensions
UploadFixer.fix_all_extensions
end

View File

@ -1,6 +1,11 @@
class UploadFixer
def self.fix_extensions
def self.fix_all_extensions
Upload.where("uploads.extension IS NOT NULL").find_each do |upload|
fix_extension_on_upload(upload)
end
end
def self.fix_extension_on_upload(upload)
is_external = Discourse.store.external?
previous_url = upload.url.dup
@ -65,9 +70,12 @@ class UploadFixer
tombstone_path
)
end
end
end
end
rescue => e
STDERR.puts "Skipping upload: ailed to correct extension on upload id: #{upload.id} #{current_extension} => #{correct_extension}"
STDERR.puts e
end
private