VBULLETIN: add some stats about the imported groups

This commit is contained in:
Régis Hanol 2014-08-25 12:33:08 +02:00
parent 7aaf718cf3
commit 9b86d1507d
2 changed files with 20 additions and 11 deletions

View file

@ -28,27 +28,32 @@ class ImportScripts::Base
@existing_posts = {}
@topic_lookup = {}
puts "loading existing groups..."
GroupCustomField.where(name: 'import_id').pluck(:group_id, :value).each do |group_id, import_id|
@existing_groups[import_id] = group_id
end
puts "loading existing users..."
UserCustomField.where(name: 'import_id').pluck(:user_id, :value).each do |user_id, import_id|
@existing_users[import_id] = user_id
end
puts "loading existing categories..."
CategoryCustomField.where(name: 'import_id').pluck(:category_id, :value).each do |category_id, import_id|
@categories_lookup[import_id] = Category.find(category_id.to_i)
end
puts "loading existing posts..."
PostCustomField.where(name: 'import_id').pluck(:post_id, :value).each do |post_id, import_id|
@existing_posts[import_id] = post_id
end
Post.joins(:topic).select("posts.id, posts.topic_id, posts.post_number, topics.slug").each do |post|
@topic_lookup[post.id] = {
topic_id: post.topic_id,
post_number: post.post_number,
url: post.url,
puts "loading existing topics..."
Post.joins(:topic).pluck("posts.id, posts.topic_id, posts.post_number, topics.slug").each do |p|
@topic_lookup[p[0]] = {
topic_id: p[1],
post_number: p[2],
url: Post.url(p[3], p[1], p[2]),
}
end
end

View file

@ -88,15 +88,12 @@ class ImportScripts::VBulletin < ImportScripts::Base
puts "", "Loading groups from '#{@options.user_group}'..."
data = File.read(@options.user_group)
@groups = CSV.parse(data, default_csv_options).map { |row| row.to_hash }
original_count = @groups.count
@all_groups = CSV.parse(data, default_csv_options).map { |row| row.to_hash }
# reject unmapped groups
if @new_group_ids.try(:size) > 0
@groups.reject! { |group| !@new_group_ids.has_key?(group[:usergroupid]) }
end
@groups = @all_groups.reject { |group| !@new_group_ids.has_key?(group[:usergroupid]) }
puts "Loaded #{@groups.count} out of #{original_count} groups!"
puts "Loaded #{@groups.count} out of #{@all_groups.count} groups!"
end
def load_users
@ -108,6 +105,13 @@ class ImportScripts::VBulletin < ImportScripts::Base
original_count = @users.count
if @mapped_groups.try(:size) > 0
# show some stats
group_ids = Set.new(@users.map { |user| user[:usergroupid].to_i })
group_ids.sort.each do |group_id|
count = @users.select { |user| user[:usergroupid].to_i == group_id }.count
group = @all_groups.select { |group| group[:usergroupid].to_i == group_id }.first.try(:[], :title)
puts "\t- #{count} users in usergroup ##{group_id} (#{group})"
end
# reject users from unmapped groups
@users.reject! { |user| !@mapped_groups.has_key?(user[:usergroupid]) }
# change mapped groups