mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
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:
parent
fc2e92d423
commit
8a5d97ef3f
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue
Block a user