mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
DEV: Update topic solutions import for new table structure (generic_bulk.rb) (#32051)
This commit is contained in:
@ -803,6 +803,8 @@ class BulkImport::Base
|
||||
|
||||
GAMIFICATION_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[
|
||||
id
|
||||
status
|
||||
@ -1115,6 +1117,10 @@ class BulkImport::Base
|
||||
create_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::Base
|
||||
score_event
|
||||
end
|
||||
|
||||
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_event
|
||||
end
|
||||
|
@ -2110,7 +2110,7 @@ class BulkImport::Generic < BulkImport::Base
|
||||
end
|
||||
|
||||
def 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::Base
|
||||
ORDER BY topic_id
|
||||
SQL
|
||||
|
||||
field_name = "is_accepted_answer"
|
||||
value = "true"
|
||||
existing_fields = PostCustomField.where(name: field_name).pluck(:post_id).to_set
|
||||
existing_solved_topics = DiscourseSolved::SolvedTopic.pluck(:topic_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
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user