DEV: Safer replacement for old scheme uploads for `posts:missing_uploads`.

DEV: Safer replacement for old scheme uploads for posts:missing_uploads.

diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake
index 38d4b28..b010d72 100644
--- a/lib/tasks/posts.rake
+++ b/lib/tasks/posts.rake
@@ -417,7 +417,6 @@ def missing_uploads
     next if sha1.present?
     puts "Fixing missing uploads: " if count_missing == 0
     count_missing += 1
-    print "."
 
     upload_id = nil
 
@@ -434,20 +433,29 @@ def missing_uploads
     end
 
     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
-        DbHelper.remap(UrlHelper.absolute(src), upload.url)
 
         post.reload
-        post.raw.gsub!(src, upload.url)
-        post.cooked.gsub!(src, upload.url)
-
-        if post.changed?
-          post.save!(validate: false)
-          post.rebake!
-        end
+        new_raw = post.raw.dup
+        new_raw = new_raw.gsub(path, upload.url)
+
+        PostRevisor.new(post, Topic.with_deleted.find_by(id: post.topic_id)).revise!(
+          Discourse.system_user,
+          {
+            raw: new_raw
+          },
+          skip_validations: true,
+          force_new_version: true,
+          bypass_bump: true
+        )
+
+        print "🆗"
+      else
+        print "❌"
       end
     else
+      print "🚫"
       old_scheme_upload_count += 1
     end

GitHub sha: a0aeabbb

1 Like

Fix typo in a0aeabbb940ec9df40625c396616d5d64b30e20f.