DEV: don't fail if in uploads:fix_missing_s3 when fix fails

Previously a single error on a file like invalid extension could fail the
entire rake task
This commit is contained in:
Sam Saffron 2020-08-18 17:55:35 +10:00
parent 92b7fe4c62
commit 2a7490149c
No known key found for this signature in database
GPG Key ID: B9606168D2FFD9F5

View File

@ -1083,23 +1083,32 @@ def fix_missing_s3
puts "Successfully downloaded upload id: #{upload.id} - #{upload.url} fixing upload" puts "Successfully downloaded upload id: #{upload.id} - #{upload.url} fixing upload"
fixed_upload = nil fixed_upload = nil
fix_error = nil
Upload.transaction do Upload.transaction do
upload.update!(sha1: SecureRandom.hex) begin
fixed_upload = UploadCreator.new(tempfile, "temp.#{upload.extension}").create_for(Discourse.system_user.id) upload.update!(sha1: SecureRandom.hex)
fixed_upload = UploadCreator.new(tempfile, "temp.#{upload.extension}").create_for(Discourse.system_user.id)
rescue => fix_error
# invalid extension is the most common issue
end
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
# we do not fix sha, it may be wrong for arbitrary reasons, if we correct it if fix_error
# we may end up breaking posts puts "Failed to fix upload #{e}"
upload.update!(etag: fixed_upload.etag, url: fixed_upload.url, verified: nil) else
# we do not fix sha, it may be wrong for arbitrary reasons, if we correct it
# we may end up breaking posts
upload.update!(etag: fixed_upload.etag, url: fixed_upload.url, verified: nil)
OptimizedImage.where(upload_id: upload.id).destroy_all OptimizedImage.where(upload_id: upload.id).destroy_all
rebake_ids = PostUpload.where(upload_id: upload.id).pluck(:post_id) rebake_ids = PostUpload.where(upload_id: upload.id).pluck(:post_id)
if rebake_ids.present? if rebake_ids.present?
Post.where(id: rebake_ids).each do |post| Post.where(id: rebake_ids).each do |post|
puts "rebake post #{post.id}" puts "rebake post #{post.id}"
post.rebake! post.rebake!
end
end end
end end
end end