Merge users based on their email in vBulletin importer

This commit is contained in:
Régis Hanol 2018-10-19 15:16:45 +02:00
parent 7166d7de9a
commit 637123ff6f
2 changed files with 10 additions and 22 deletions

View File

@ -2,28 +2,16 @@ module ImportScripts
class LookupContainer class LookupContainer
def initialize def initialize
puts 'Loading existing groups...' puts 'Loading existing groups...'
@groups = {} @groups = GroupCustomField.where(name: 'import_id').pluck(:value, :group_id).to_h
GroupCustomField.where(name: 'import_id').pluck(:group_id, :value).each do |group_id, import_id|
@groups[import_id] = group_id
end
puts 'Loading existing users...' puts 'Loading existing users...'
@users = {} @users = UserCustomField.where(name: 'import_id').pluck(:value, :user_id).to_h
UserCustomField.where(name: 'import_id').pluck(:user_id, :value).each do |user_id, import_id|
@users[import_id] = user_id
end
puts 'Loading existing categories...' puts 'Loading existing categories...'
@categories = {} @categories = CategoryCustomField.where(name: 'import_id').pluck(:value, :category_id).to_h
CategoryCustomField.where(name: 'import_id').pluck(:category_id, :value).each do |category_id, import_id|
@categories[import_id] = category_id
end
puts 'Loading existing posts...' puts 'Loading existing posts...'
@posts = {} @posts = PostCustomField.where(name: 'import_id').pluck(:value, :post_id).to_h
PostCustomField.where(name: 'import_id').pluck(:post_id, :value).each do |post_id, import_id|
@posts[import_id] = post_id
end
puts 'Loading existing topics...' puts 'Loading existing topics...'
@topics = {} @topics = {}
@ -73,19 +61,19 @@ module ImportScripts
end end
def add_group(import_id, group) def add_group(import_id, group)
@groups[import_id] = group.id @groups[import_id.to_s] = group.id
end end
def add_user(import_id, user) def add_user(import_id, user)
@users[import_id] = user.id @users[import_id.to_s] = user.id
end end
def add_category(import_id, category) def add_category(import_id, category)
@categories[import_id] = category.id @categories[import_id.to_s] = category.id
end end
def add_post(import_id, post) def add_post(import_id, post)
@posts[import_id] = post.id @posts[import_id.to_s] = post.id
end end
def add_topic(post) def add_topic(post)

View File

@ -146,7 +146,7 @@ EOM
last_user_id = users[-1]["userid"] last_user_id = users[-1]["userid"]
before = users.size before = users.size
users.reject! { |u| @lookup.user_already_imported?(u["userid"].to_i) } users.reject! { |u| @lookup.user_already_imported?(u["userid"]) }
create_users(users, total: user_count, offset: offset) do |user| create_users(users, total: user_count, offset: offset) do |user|
email = user["email"].presence || fake_email email = user["email"].presence || fake_email
@ -162,6 +162,7 @@ EOM
username: username, username: username,
password: password, password: password,
email: email, email: email,
merge: true,
website: user["homepage"].strip, website: user["homepage"].strip,
title: @htmlentities.decode(user["usertitle"]).strip, title: @htmlentities.decode(user["usertitle"]).strip,
primary_group_id: group_id_from_imported_group_id(user["usergroupid"].to_i), primary_group_id: group_id_from_imported_group_id(user["usergroupid"].to_i),
@ -176,7 +177,6 @@ EOM
end end
@usernames = UserCustomField.joins(:user).where(name: 'import_username').pluck('user_custom_fields.value', 'users.username').to_h @usernames = UserCustomField.joins(:user).where(name: 'import_username').pluck('user_custom_fields.value', 'users.username').to_h
end end
def create_groups_membership def create_groups_membership