A platform for community discussion. Free, open, simple.
DEV: Update topic solutions import for new table structure (generic_bulk.rb) (#32051)
Ahmed Gagan1ede31b7043a
diff --git a/script/bulk_import/base.rb b/script/bulk_import/base.rbindex 70e01022382..6d7cb130bcc 100644--- a/script/bulk_import/base.rb+++ b/script/bulk_import/base.rb@@ -803,6 +803,8 @@ class BulkImport::BaseGAMIFICATION_SCORE_EVENT_COLUMNS = %i[user_id date points description created_at updated_at]+ SOLVED_TOPIC_COLUMNS = %i[topic_id answer_post_id accepter_user_id created_at updated_at]+POST_EVENT_COLUMNS = %i[idstatus@@ -1115,6 +1117,10 @@ class BulkImport::Basecreate_records(rows, "gamification_score_event", GAMIFICATION_SCORE_EVENT_COLUMNS, &block)end+ def create_solved_topic(rows, &block)+ create_records(rows, "discourse_solved_solved_topics", SOLVED_TOPIC_COLUMNS, &block)+ end+def create_post_events(rows, &block)create_records(rows, "discourse_post_event_events", POST_EVENT_COLUMNS, &block)end@@ -1817,6 +1823,13 @@ class BulkImport::Basescore_eventend+ def process_discourse_solved_solved_topics(solved_topic)+ solved_topic[:created_at] ||= NOW+ solved_topic[:updated_at] ||= NOW+ solved_topic[:accepter_user_id] ||= Discourse::SYSTEM_USER_ID+ solved_topic+ end+def process_discourse_post_event_events(post_event)post_eventenddiff --git a/script/bulk_import/generic_bulk.rb b/script/bulk_import/generic_bulk.rbindex 5bf413d3d05..782fd46f91e 100644--- a/script/bulk_import/generic_bulk.rb+++ b/script/bulk_import/generic_bulk.rb@@ -2110,7 +2110,7 @@ class BulkImport::Generic < BulkImport::Baseenddef import_answers- puts "", "Importing solutions into post custom fields..."+ puts "", "Importing solutions into discourse_solved_solved_topics..."solutions = query(<<~SQL)SELECT *@@ -2118,40 +2118,20 @@ class BulkImport::Generic < BulkImport::BaseORDER BY topic_idSQL- field_name = "is_accepted_answer"- value = "true"- existing_fields = PostCustomField.where(name: field_name).pluck(:post_id).to_set-- create_post_custom_fields(solutions) do |row|- next unless (post_id = post_id_from_imported_id(row["post_id"]))- next unless existing_fields.add?(post_id)-- {- post_id: post_id,- name: field_name,- value: value,- created_at: to_datetime(row["created_at"]),- }- end+ existing_solved_topics = DiscourseSolved::SolvedTopic.pluck(:topic_id).to_set- puts "", "Importing solutions into topic custom fields..."-- solutions.reset-- field_name = "accepted_answer_post_id"- existing_fields = TopicCustomField.where(name: field_name).pluck(:topic_id).to_set-- create_topic_custom_fields(solutions) do |row|+ create_solved_topic(solutions) do |row|post_id = post_id_from_imported_id(row["post_id"])topic_id = topic_id_from_imported_id(row["topic_id"])+ accepter_user_id = user_id_from_imported_id(row["acting_user_id"])next unless post_id && topic_id- next unless existing_fields.add?(topic_id)+ next unless existing_solved_topics.add?(topic_id){topic_id: topic_id,- name: field_name,- value: post_id.to_s,+ answer_post_id: post_id,+ accepter_user_id: accepter_user_id,created_at: to_datetime(row["created_at"]),}end