mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
parent
92b7fe4c62
commit
2a7490149c
@ -1083,12 +1083,20 @@ 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
|
||||||
|
begin
|
||||||
upload.update!(sha1: SecureRandom.hex)
|
upload.update!(sha1: SecureRandom.hex)
|
||||||
fixed_upload = UploadCreator.new(tempfile, "temp.#{upload.extension}").create_for(Discourse.system_user.id)
|
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
|
||||||
|
|
||||||
|
if fix_error
|
||||||
|
puts "Failed to fix upload #{e}"
|
||||||
|
else
|
||||||
# we do not fix sha, it may be wrong for arbitrary reasons, if we correct it
|
# we do not fix sha, it may be wrong for arbitrary reasons, if we correct it
|
||||||
# we may end up breaking posts
|
# we may end up breaking posts
|
||||||
upload.update!(etag: fixed_upload.etag, url: fixed_upload.url, verified: nil)
|
upload.update!(etag: fixed_upload.etag, url: fixed_upload.url, verified: nil)
|
||||||
@ -1104,6 +1112,7 @@ def fix_missing_s3
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
puts "Attempting to automatically fix problem uploads"
|
puts "Attempting to automatically fix problem uploads"
|
||||||
puts
|
puts
|
||||||
|
Loading…
Reference in New Issue
Block a user