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

View File

@ -146,7 +146,7 @@ EOM
last_user_id = users[-1]["userid"]
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|
email = user["email"].presence || fake_email
@ -162,6 +162,7 @@ EOM
username: username,
password: password,
email: email,
merge: true,
website: user["homepage"].strip,
title: @htmlentities.decode(user["usertitle"]).strip,
primary_group_id: group_id_from_imported_group_id(user["usergroupid"].to_i),
@ -176,7 +177,6 @@ EOM
end
@usernames = UserCustomField.joins(:user).where(name: 'import_username').pluck('user_custom_fields.value', 'users.username').to_h
end
def create_groups_membership