mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 23:44:48 +08:00
DEV: Safer replacement for old scheme uploads for posts:missing_uploads
.
This commit is contained in:
@ -417,7 +417,6 @@ def missing_uploads
|
|||||||
next if sha1.present?
|
next if sha1.present?
|
||||||
puts "Fixing missing uploads: " if count_missing == 0
|
puts "Fixing missing uploads: " if count_missing == 0
|
||||||
count_missing += 1
|
count_missing += 1
|
||||||
print "."
|
|
||||||
|
|
||||||
upload_id = nil
|
upload_id = nil
|
||||||
|
|
||||||
@ -434,20 +433,29 @@ def missing_uploads
|
|||||||
end
|
end
|
||||||
|
|
||||||
if file_path.present?
|
if file_path.present?
|
||||||
if upload = UploadCreator.new(File.open(file_path), File.basename(path)).create_for(Discourse.system_user.id)
|
if (upload = UploadCreator.new(File.open(file_path), File.basename(path)).create_for(Discourse.system_user.id)).presisted?
|
||||||
upload_id = upload.id
|
upload_id = upload.id
|
||||||
DbHelper.remap(UrlHelper.absolute(src), upload.url)
|
|
||||||
|
|
||||||
post.reload
|
post.reload
|
||||||
post.raw.gsub!(src, upload.url)
|
new_raw = post.raw.dup
|
||||||
post.cooked.gsub!(src, upload.url)
|
new_raw = new_raw.gsub(path, upload.url)
|
||||||
|
|
||||||
if post.changed?
|
PostRevisor.new(post, Topic.with_deleted.find_by(id: post.topic_id)).revise!(
|
||||||
post.save!(validate: false)
|
Discourse.system_user,
|
||||||
post.rebake!
|
{
|
||||||
end
|
raw: new_raw
|
||||||
|
},
|
||||||
|
skip_validations: true,
|
||||||
|
force_new_version: true,
|
||||||
|
bypass_bump: true
|
||||||
|
)
|
||||||
|
|
||||||
|
print "🆗"
|
||||||
|
else
|
||||||
|
print "❌"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
print "🚫"
|
||||||
old_scheme_upload_count += 1
|
old_scheme_upload_count += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user