DEV: Update importers from PostUpload to UploadReference (#23681)

Discourse stopped using PostUpload in 9db8f00b3d. 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.
This commit is contained in:
David Taylor 2023-09-27 15:01:04 +01:00 committed by GitHub
parent fc2e92d423
commit 8a5d97ef3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 16 deletions

View File

@ -2,6 +2,8 @@
require_relative "base" require_relative "base"
raise "This importer needs to be updated from using PostUpload to UploadReference"
class BulkImport::DiscourseMerger < BulkImport::Base class BulkImport::DiscourseMerger < BulkImport::Base
NOW ||= "now()" NOW ||= "now()"
CUSTOM_FIELDS = %w[category group post topic user] CUSTOM_FIELDS = %w[category group post topic user]

View File

@ -310,9 +310,7 @@ class ImportScripts::Bbpress < ImportScripts::Base
if !post.raw[html] if !post.raw[html]
post.raw << "\n\n" << html post.raw << "\n\n" << html
post.save! post.save!
unless PostUpload.where(post: post, upload: upload).exists? UploadReference.ensure_exist!(upload_ids: [upload.id], target: post)
PostUpload.create!(post: post, upload: upload)
end
end end
end end
end end
@ -360,9 +358,7 @@ class ImportScripts::Bbpress < ImportScripts::Base
if !post.raw[html] if !post.raw[html]
post.raw << "\n\n" << html post.raw << "\n\n" << html
post.save! post.save!
unless PostUpload.where(post: post, upload: upload).exists? UploadReference.ensure_exist!(upload_ids: [upload.id], target: post)
PostUpload.create!(post: post, upload: upload)
end
end end
end end
end end

View File

@ -189,9 +189,7 @@ class ImportScripts::HigherLogic < ImportScripts::Base
post.raw << "\n\n" << html post.raw << "\n\n" << html
post.save! post.save!
unless PostUpload.where(post: post, upload: upload).exists? UploadReference.ensure_exist!(upload_ids: [upload.id], target: post)
PostUpload.create!(post: post, upload: upload)
end
end end
end end
end end

View File

@ -270,10 +270,10 @@ class ImportScripts::Phorum < ImportScripts::Base
if !post.raw[html] if !post.raw[html]
post.raw += "\n\n#{html}\n\n" post.raw += "\n\n#{html}\n\n"
post.save! 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"]}" puts "skipping creating uploaded for previously uploaded file #{upload["file_id"]}"
else else
PostUpload.create!(post: post, upload: upl_obj) UploadReference.ensure_exist!(upload_ids: [upl_obj.id], target: post)
end end
# PostUpload.create!(post: post, upload: upl_obj) unless PostUpload.where(post: post, upload: upl_obj).exists? # PostUpload.create!(post: post, upload: upl_obj) unless PostUpload.where(post: post, upload: upl_obj).exists?
else else

View File

@ -452,10 +452,10 @@ class ImportScripts::Smf1 < ImportScripts::Base
if upload = create_upload(post.user_id, path, u["filename"]) if upload = create_upload(post.user_id, path, u["filename"])
html = html_for_upload(upload, 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.raw += "\n\n#{html}\n\n"
post.save post.save
PostUpload.create(upload: upload, post: post) UploadReference.ensure_exist!(upload_ids: [upload.id], target: post)
end end
end end

View File

@ -439,9 +439,7 @@ class ImportScripts::VBulletin < ImportScripts::Base
if !post.raw[html] if !post.raw[html]
post.raw += "\n\n#{html}\n\n" post.raw += "\n\n#{html}\n\n"
post.save! post.save!
unless PostUpload.where(post: post, upload: upl_obj).exists? UploadReference.ensure_exist!(upload_ids: [upl_obj.id], target: post)
PostUpload.create!(post: post, upload: upl_obj)
end
end end
else else
puts "Fail" puts "Fail"