mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 22:53:56 +08:00
Bulk import likes from vBulletin thanks (#5014)
This commit is contained in:
parent
7ee861f457
commit
bac21d317b
|
@ -110,6 +110,9 @@ class BulkImport::Base
|
||||||
@last_post_id = Post.unscoped.maximum(:id)
|
@last_post_id = Post.unscoped.maximum(:id)
|
||||||
@post_number_by_post_id = Post.unscoped.pluck(:id, :post_number).to_h
|
@post_number_by_post_id = Post.unscoped.pluck(:id, :post_number).to_h
|
||||||
@topic_id_by_post_id = Post.unscoped.pluck(:id, :topic_id).to_h
|
@topic_id_by_post_id = Post.unscoped.pluck(:id, :topic_id).to_h
|
||||||
|
|
||||||
|
puts "Loading post actions indexes..."
|
||||||
|
@last_post_action_id = PostAction.unscoped.maximum(:id) || 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
|
@ -124,6 +127,7 @@ class BulkImport::Base
|
||||||
@raw_connection.exec("SELECT setval('#{Category.sequence_name}', #{@last_category_id})")
|
@raw_connection.exec("SELECT setval('#{Category.sequence_name}', #{@last_category_id})")
|
||||||
@raw_connection.exec("SELECT setval('#{Topic.sequence_name}', #{@last_topic_id})")
|
@raw_connection.exec("SELECT setval('#{Topic.sequence_name}', #{@last_topic_id})")
|
||||||
@raw_connection.exec("SELECT setval('#{Post.sequence_name}', #{@last_post_id})")
|
@raw_connection.exec("SELECT setval('#{Post.sequence_name}', #{@last_post_id})")
|
||||||
|
@raw_connection.exec("SELECT setval('#{PostAction.sequence_name}', #{@last_post_action_id})")
|
||||||
end
|
end
|
||||||
|
|
||||||
def group_id_from_imported_id(id); @groups[id.to_s]; end
|
def group_id_from_imported_id(id); @groups[id.to_s]; end
|
||||||
|
@ -179,6 +183,12 @@ class BulkImport::Base
|
||||||
like_count raw cooked hidden word_count created_at last_version_at updated_at
|
like_count raw cooked hidden word_count created_at last_version_at updated_at
|
||||||
}
|
}
|
||||||
|
|
||||||
|
POST_ACTION_COLUMNS ||= %i{
|
||||||
|
id post_id user_id post_action_type_id deleted_at created_at updated_at
|
||||||
|
deleted_by_id related_post_id staff_took_action deferred_by_id targets_topic
|
||||||
|
agreed_at agreed_by_id deferred_at disagreed_at disagreed_by_id
|
||||||
|
}
|
||||||
|
|
||||||
TOPIC_ALLOWED_USER_COLUMNS ||= %i{
|
TOPIC_ALLOWED_USER_COLUMNS ||= %i{
|
||||||
topic_id user_id created_at updated_at
|
topic_id user_id created_at updated_at
|
||||||
}
|
}
|
||||||
|
@ -205,6 +215,7 @@ class BulkImport::Base
|
||||||
def create_categories(rows, &block); create_records(rows, "category", CATEGORY_COLUMNS, &block); end
|
def create_categories(rows, &block); create_records(rows, "category", CATEGORY_COLUMNS, &block); end
|
||||||
def create_topics(rows, &block); create_records(rows, "topic", TOPIC_COLUMNS, &block); end
|
def create_topics(rows, &block); create_records(rows, "topic", TOPIC_COLUMNS, &block); end
|
||||||
def create_posts(rows, &block); create_records(rows, "post", POST_COLUMNS, &block); end
|
def create_posts(rows, &block); create_records(rows, "post", POST_COLUMNS, &block); end
|
||||||
|
def create_post_actions(rows, &block); create_records(rows, "post_action", POST_ACTION_COLUMNS, &block); end
|
||||||
def create_topic_allowed_users(rows, &block); create_records(rows, "topic_allowed_user", TOPIC_ALLOWED_USER_COLUMNS, &block); end
|
def create_topic_allowed_users(rows, &block); create_records(rows, "topic_allowed_user", TOPIC_ALLOWED_USER_COLUMNS, &block); end
|
||||||
|
|
||||||
def process_group(group)
|
def process_group(group)
|
||||||
|
@ -358,6 +369,15 @@ class BulkImport::Base
|
||||||
post
|
post
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def process_post_action(post_action)
|
||||||
|
post_action[:id] ||= @last_post_action_id += 1
|
||||||
|
post_action[:staff_took_action] ||= false
|
||||||
|
post_action[:targets_topic] ||= false
|
||||||
|
post_action[:created_at] ||= NOW
|
||||||
|
post_action[:updated_at] ||= post_action[:created_at]
|
||||||
|
post_action
|
||||||
|
end
|
||||||
|
|
||||||
def process_topic_allowed_user(topic_allowed_user)
|
def process_topic_allowed_user(topic_allowed_user)
|
||||||
topic_allowed_user[:created_at] = NOW
|
topic_allowed_user[:created_at] = NOW
|
||||||
topic_allowed_user[:updated_at] = NOW
|
topic_allowed_user[:updated_at] = NOW
|
||||||
|
|
|
@ -93,6 +93,8 @@ class BulkImport::VBulletin < BulkImport::Base
|
||||||
import_topics
|
import_topics
|
||||||
import_posts
|
import_posts
|
||||||
|
|
||||||
|
import_likes
|
||||||
|
|
||||||
import_private_topics
|
import_private_topics
|
||||||
import_topic_allowed_users
|
import_topic_allowed_users
|
||||||
import_private_posts
|
import_private_posts
|
||||||
|
@ -383,6 +385,36 @@ class BulkImport::VBulletin < BulkImport::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def import_likes
|
||||||
|
return unless @has_post_thanks
|
||||||
|
puts "Importing likes..."
|
||||||
|
|
||||||
|
@imported_likes = Set.new
|
||||||
|
@last_imported_post_id = 0
|
||||||
|
|
||||||
|
post_thanks = mysql_stream <<-SQL
|
||||||
|
SELECT postid, userid, date
|
||||||
|
FROM post_thanks
|
||||||
|
WHERE postid > #{@last_imported_post_id}
|
||||||
|
ORDER BY postid
|
||||||
|
SQL
|
||||||
|
|
||||||
|
create_post_actions(post_thanks) do |row|
|
||||||
|
post_id = post_id_from_imported_id(row[0])
|
||||||
|
user_id = user_id_from_imported_id(row[1])
|
||||||
|
|
||||||
|
next if post_id.nil? || user_id.nil?
|
||||||
|
next if @imported_likes.add?([post_id, user_id]).nil?
|
||||||
|
|
||||||
|
{
|
||||||
|
post_id: post_id_from_imported_id(row[0]),
|
||||||
|
user_id: user_id_from_imported_id(row[1]),
|
||||||
|
post_action_type_id: 2,
|
||||||
|
created_at: Time.zone.at(row[2])
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def import_private_topics
|
def import_private_topics
|
||||||
puts "Importing private topics..."
|
puts "Importing private topics..."
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user