DEV: fix_missing_s3 attempts to re-download if missing
unverified uploads get re-downloaded and corrected if they exist in the task
This commit is contained in:
parent
bd0a7553c4
commit
f48fa30ecd
|
@ -1065,6 +1065,27 @@ end
|
||||||
|
|
||||||
def fix_missing_s3
|
def fix_missing_s3
|
||||||
Jobs.run_immediately!
|
Jobs.run_immediately!
|
||||||
|
|
||||||
|
puts "Attempting to download missing uploads and recreate"
|
||||||
|
ids = Upload.where(verified: false).pluck(:id)
|
||||||
|
ids.each do |id|
|
||||||
|
upload = Upload.find(id)
|
||||||
|
|
||||||
|
tempfile = FileHelper.download(upload.url, max_file_size: 30.megabyte, tmp_file_name: "#{SecureRandom.hex}.#{upload.extension}")
|
||||||
|
if tempfile
|
||||||
|
puts "Successfully downloaded upload id: #{upload.id} - #{upload.url} fixing upload"
|
||||||
|
|
||||||
|
fixed_upload = nil
|
||||||
|
Upload.transaction do
|
||||||
|
upload.update!(sha1: SecureRandom.hex)
|
||||||
|
fixed_upload = UploadCreator.new(tempfile, "temp.#{upload.extension}").create_for(Discourse.system_user.id)
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
|
|
||||||
|
upload.update!(etag: fixed_upload.etag, sha1: fixed_upload.sha1, url: fixed_upload.url, verified: nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
puts "Attempting to automatically fix problem uploads"
|
puts "Attempting to automatically fix problem uploads"
|
||||||
puts
|
puts
|
||||||
puts "Rebaking posts with missing uploads, this can take a while as all rebaking runs inline"
|
puts "Rebaking posts with missing uploads, this can take a while as all rebaking runs inline"
|
||||||
|
|
Loading…
Reference in New Issue