mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
Adding Import Support for Discourse Reactions Plugin (#30361)
* Adding Import Support for Discourse Reactions Plugin --------- Co-authored-by: Gerhard Schlager <gerhard.schlager@discourse.org>
This commit is contained in:
@ -120,6 +120,7 @@ class BulkImport::Base
|
||||
chat_channel: 6,
|
||||
chat_thread: 7,
|
||||
chat_message: 8,
|
||||
discourse_reactions_reaction: 9,
|
||||
)
|
||||
|
||||
def create_migration_mappings_table
|
||||
@ -309,6 +310,10 @@ class BulkImport::Base
|
||||
|
||||
@chat_message_mapping = load_index(MAPPING_TYPES[:chat_message])
|
||||
@last_chat_message_id = last_id(Chat::Message)
|
||||
|
||||
puts "Loading reaction indexes..."
|
||||
@discourse_reaction_mapping = load_index(MAPPING_TYPES[:discourse_reactions_reaction])
|
||||
@last_discourse_reaction_id = last_id(DiscourseReactions::Reaction)
|
||||
end
|
||||
|
||||
def use_bbcode_to_md?
|
||||
@ -390,6 +395,11 @@ class BulkImport::Base
|
||||
"SELECT setval('#{Chat::Message.sequence_name}', #{@last_chat_message_id})",
|
||||
)
|
||||
end
|
||||
if @last_discourse_reaction_id > 0
|
||||
@raw_connection.exec(
|
||||
"SELECT setval('#{DiscourseReactions::Reaction.sequence_name}', #{@last_discourse_reaction_id})",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def group_id_from_imported_id(id)
|
||||
@ -475,6 +485,10 @@ class BulkImport::Base
|
||||
@chat_message_mapping[id.to_s]&.to_i
|
||||
end
|
||||
|
||||
def discourse_reaction_id_from_original_id(id)
|
||||
@discourse_reaction_mapping[id.to_s]&.to_i
|
||||
end
|
||||
|
||||
GROUP_COLUMNS = %i[
|
||||
id
|
||||
name
|
||||
@ -925,6 +939,18 @@ class BulkImport::Base
|
||||
|
||||
CHAT_MENTION_COLUMNS = %i[chat_message_id target_id type created_at updated_at]
|
||||
|
||||
REACTION_USER_COLUMNS = %i[reaction_id user_id created_at updated_at post_id]
|
||||
|
||||
REACTION_COLUMNS = %i[
|
||||
id
|
||||
post_id
|
||||
reaction_type
|
||||
reaction_value
|
||||
reaction_users_count
|
||||
created_at
|
||||
updated_at
|
||||
]
|
||||
|
||||
def create_groups(rows, &block)
|
||||
create_records(rows, "group", GROUP_COLUMNS, &block)
|
||||
end
|
||||
@ -1157,6 +1183,14 @@ class BulkImport::Base
|
||||
create_records(rows, "chat_mention", CHAT_MENTION_COLUMNS, &block)
|
||||
end
|
||||
|
||||
def create_reaction_users(rows, &block)
|
||||
create_records(rows, "discourse_reactions_reaction_user", REACTION_USER_COLUMNS, &block)
|
||||
end
|
||||
|
||||
def create_reactions(rows, &block)
|
||||
create_records_with_mapping(rows, "discourse_reactions_reaction", REACTION_COLUMNS, &block)
|
||||
end
|
||||
|
||||
def process_group(group)
|
||||
@groups[group[:imported_id].to_i] = group[:id] = @last_group_id += 1
|
||||
|
||||
@ -1962,6 +1996,24 @@ class BulkImport::Base
|
||||
mention
|
||||
end
|
||||
|
||||
def process_discourse_reactions_reaction_user(reaction_user)
|
||||
reaction_user[:created_at] ||= NOW
|
||||
reaction_user[:updated_at] ||= NOW
|
||||
reaction_user
|
||||
end
|
||||
|
||||
def process_discourse_reactions_reaction(reaction)
|
||||
reaction[:id] = @last_discourse_reaction_id += 1
|
||||
reaction[:created_at] ||= NOW
|
||||
reaction[:updated_at] ||= NOW
|
||||
reaction[:reaction_users_count] ||= 0
|
||||
|
||||
@imported_records[reaction[:original_id].to_s] = reaction[:id]
|
||||
@discourse_reaction_mapping[reaction[:original_id].to_s] = reaction[:id]
|
||||
|
||||
reaction
|
||||
end
|
||||
|
||||
def create_records(all_rows, name, columns, &block)
|
||||
start = Time.now
|
||||
imported_ids = []
|
||||
|
Reference in New Issue
Block a user