mirror of
https://github.com/discourse/discourse.git
synced 2025-04-16 20:59:06 +08:00
FIX: in import scripts, fix a case where post author lookup fails for some reason
This commit is contained in:
parent
ce732d2252
commit
916252483b
@ -70,7 +70,11 @@ class ImportScripts::Base
|
|||||||
|
|
||||||
# Get the Discourse User id based on the id of the source user
|
# Get the Discourse User id based on the id of the source user
|
||||||
def user_id_from_imported_user_id(import_id)
|
def user_id_from_imported_user_id(import_id)
|
||||||
@existing_users[import_id] || @existing_users[import_id.to_s]
|
@existing_users[import_id] || @existing_users[import_id.to_s] || find_user_by_import_id(import_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_user_by_import_id(import_id)
|
||||||
|
UserCustomField.where(name: 'import_id', value: import_id.to_s).first.try(:user)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the Discourse Category id based on the id of the source category
|
# Get the Discourse Category id based on the id of the source category
|
||||||
@ -98,6 +102,7 @@ class ImportScripts::Base
|
|||||||
# create the Discourse user record.
|
# create the Discourse user record.
|
||||||
def create_users(results)
|
def create_users(results)
|
||||||
puts "creating users"
|
puts "creating users"
|
||||||
|
num_users_before = User.count
|
||||||
users_created = 0
|
users_created = 0
|
||||||
users_skipped = 0
|
users_skipped = 0
|
||||||
progress = 0
|
progress = 0
|
||||||
@ -126,7 +131,7 @@ class ImportScripts::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
puts ''
|
puts ''
|
||||||
puts "created: #{users_created} users"
|
puts "created: #{User.count - num_users_before} users"
|
||||||
puts " failed: #{@failed_users.size}" if @failed_users.size > 0
|
puts " failed: #{@failed_users.size}" if @failed_users.size > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -159,10 +164,6 @@ class ImportScripts::Base
|
|||||||
u # If there was an error creating the user, u.errors has the messages
|
u # If there was an error creating the user, u.errors has the messages
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_user_by_import_id(import_id)
|
|
||||||
UserCustomField.where(name: 'import_id', value: import_id.to_s).first.try(:user)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Iterates through a collection to create categories.
|
# Iterates through a collection to create categories.
|
||||||
# The block should return a hash with attributes for the new category.
|
# The block should return a hash with attributes for the new category.
|
||||||
# Required fields are :id and :name, where :id is the id of the
|
# Required fields are :id and :name, where :id is the id of the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user