Adding import of topic custom fields

This commit is contained in:
cocococosti 2024-05-14 17:26:06 -04:00
parent 1008a064ee
commit 08521f59ca
No known key found for this signature in database
GPG Key ID: FDEE4E9ED2BD9B89
1 changed files with 27 additions and 0 deletions

View File

@ -80,6 +80,7 @@ class BulkImport::Generic < BulkImport::Base
import_topics
import_posts
import_topic_custom_fields
import_post_custom_fields
import_polls
@ -1073,6 +1074,32 @@ class BulkImport::Generic < BulkImport::Base
post_custom_fields.close
end
def import_topic_custom_fields
puts "", "Importing topic custom fields..."
topic_custom_fields = query(<<~SQL)
SELECT *
FROM topic_custom_fields
ORDER BY topic_id, name
SQL
field_names =
query("SELECT DISTINCT name FROM topic_custom_fields") { _1.map { |row| row["name"] } }
existing_topic_custom_fields =
TopicCustomField.where(name: field_names).pluck(:topic_id, :name).to_set
create_topic_custom_fields(topic_custom_fields) do |row|
topic_id = topic_id_from_imported_id(row["topic_id"])
next if topic_id.nil?
next if existing_topic_custom_fields.include?([topic_id, row["name"]])
{ topic_id: topic_id, name: row["name"], value: row["value"] }
end
topic_custom_fields.close
end
def import_polls
unless defined?(::Poll)
puts "", "Skipping polls, because the poll plugin is not installed."