From 8a5d97ef3f6f2d29a4e58b325f15b325c7d62986 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 27 Sep 2023 15:01:04 +0100 Subject: [PATCH] DEV: Update importers from PostUpload to UploadReference (#23681) Discourse stopped using PostUpload in https://github.com/discourse/discourse/commit/9db8f00b3dd6f2881adf1b786e29426889225e7a. Since then, these importers have been writing to the table, but any data was totally unused. This commit updates the easy cases to use UploadReference, and adds an error to the discourse_merger import script, which needs more significant work. --- script/bulk_import/discourse_merger.rb | 2 ++ script/import_scripts/bbpress.rb | 8 ++------ script/import_scripts/higher_logic.rb | 4 +--- script/import_scripts/phorum.rb | 4 ++-- script/import_scripts/smf1.rb | 4 ++-- script/import_scripts/vbulletin5.rb | 4 +--- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/script/bulk_import/discourse_merger.rb b/script/bulk_import/discourse_merger.rb index 61106e6bf35..75d65bcd40d 100644 --- a/script/bulk_import/discourse_merger.rb +++ b/script/bulk_import/discourse_merger.rb @@ -2,6 +2,8 @@ require_relative "base" +raise "This importer needs to be updated from using PostUpload to UploadReference" + class BulkImport::DiscourseMerger < BulkImport::Base NOW ||= "now()" CUSTOM_FIELDS = %w[category group post topic user] diff --git a/script/import_scripts/bbpress.rb b/script/import_scripts/bbpress.rb index 4864ba6b94f..9fa95b0c50c 100644 --- a/script/import_scripts/bbpress.rb +++ b/script/import_scripts/bbpress.rb @@ -310,9 +310,7 @@ class ImportScripts::Bbpress < ImportScripts::Base if !post.raw[html] post.raw << "\n\n" << html post.save! - unless PostUpload.where(post: post, upload: upload).exists? - PostUpload.create!(post: post, upload: upload) - end + UploadReference.ensure_exist!(upload_ids: [upload.id], target: post) end end end @@ -360,9 +358,7 @@ class ImportScripts::Bbpress < ImportScripts::Base if !post.raw[html] post.raw << "\n\n" << html post.save! - unless PostUpload.where(post: post, upload: upload).exists? - PostUpload.create!(post: post, upload: upload) - end + UploadReference.ensure_exist!(upload_ids: [upload.id], target: post) end end end diff --git a/script/import_scripts/higher_logic.rb b/script/import_scripts/higher_logic.rb index 06820311264..2090d03d0f8 100644 --- a/script/import_scripts/higher_logic.rb +++ b/script/import_scripts/higher_logic.rb @@ -189,9 +189,7 @@ class ImportScripts::HigherLogic < ImportScripts::Base post.raw << "\n\n" << html post.save! - unless PostUpload.where(post: post, upload: upload).exists? - PostUpload.create!(post: post, upload: upload) - end + UploadReference.ensure_exist!(upload_ids: [upload.id], target: post) end end end diff --git a/script/import_scripts/phorum.rb b/script/import_scripts/phorum.rb index f03db50ea42..d76393fc014 100644 --- a/script/import_scripts/phorum.rb +++ b/script/import_scripts/phorum.rb @@ -270,10 +270,10 @@ class ImportScripts::Phorum < ImportScripts::Base if !post.raw[html] post.raw += "\n\n#{html}\n\n" post.save! - if PostUpload.where(post: post, upload: upl_obj).exists? + if UploadReference.where(target: post, upload: upl_obj).exists? puts "skipping creating uploaded for previously uploaded file #{upload["file_id"]}" else - PostUpload.create!(post: post, upload: upl_obj) + UploadReference.ensure_exist!(upload_ids: [upl_obj.id], target: post) end # PostUpload.create!(post: post, upload: upl_obj) unless PostUpload.where(post: post, upload: upl_obj).exists? else diff --git a/script/import_scripts/smf1.rb b/script/import_scripts/smf1.rb index 5d601f2fa2e..641d33862ea 100644 --- a/script/import_scripts/smf1.rb +++ b/script/import_scripts/smf1.rb @@ -452,10 +452,10 @@ class ImportScripts::Smf1 < ImportScripts::Base if upload = create_upload(post.user_id, path, u["filename"]) html = html_for_upload(upload, u["filename"]) - unless post.raw[html] || PostUpload.where(upload: upload, post: post).exists? + unless post.raw[html] || UploadReference.where(upload: upload, target: post).exists? post.raw += "\n\n#{html}\n\n" post.save - PostUpload.create(upload: upload, post: post) + UploadReference.ensure_exist!(upload_ids: [upload.id], target: post) end end diff --git a/script/import_scripts/vbulletin5.rb b/script/import_scripts/vbulletin5.rb index af62c0a6bb2..187ae262d4a 100644 --- a/script/import_scripts/vbulletin5.rb +++ b/script/import_scripts/vbulletin5.rb @@ -439,9 +439,7 @@ class ImportScripts::VBulletin < ImportScripts::Base if !post.raw[html] post.raw += "\n\n#{html}\n\n" post.save! - unless PostUpload.where(post: post, upload: upl_obj).exists? - PostUpload.create!(post: post, upload: upl_obj) - end + UploadReference.ensure_exist!(upload_ids: [upl_obj.id], target: post) end else puts "Fail"