From 916252483bc505b589f1b9be02a9f5ca89b1d9d8 Mon Sep 17 00:00:00 2001
From: Neil Lalonde <neillalonde@gmail.com>
Date: Wed, 11 Jun 2014 13:47:45 -0400
Subject: [PATCH] FIX: in import scripts, fix a case where post author lookup
 fails for some reason

---
 script/import_scripts/base.rb | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/script/import_scripts/base.rb b/script/import_scripts/base.rb
index 1292724607f..f6bdd3f758f 100644
--- a/script/import_scripts/base.rb
+++ b/script/import_scripts/base.rb
@@ -70,7 +70,11 @@ class ImportScripts::Base
 
   # Get the Discourse User id based on the id of the source user
   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
 
   # 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.
   def create_users(results)
     puts "creating users"
+    num_users_before = User.count
     users_created = 0
     users_skipped = 0
     progress = 0
@@ -126,7 +131,7 @@ class ImportScripts::Base
     end
 
     puts ''
-    puts "created: #{users_created} users"
+    puts "created: #{User.count - num_users_before} users"
     puts " failed: #{@failed_users.size}" if @failed_users.size > 0
   end
 
@@ -159,10 +164,6 @@ class ImportScripts::Base
     u # If there was an error creating the user, u.errors has the messages
   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.
   # 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