Merge pull request #3823 from gschlager/phpbb3-importer

FIX: phpBB3 importer failed to import users
This commit is contained in:
Neil Lalonde 2015-10-07 19:08:05 -04:00
commit 91fdfa986f
6 changed files with 29 additions and 11 deletions

View File

@ -198,12 +198,7 @@ class ImportScripts::Base
return false if import_ids.empty?
existing = "#{type.to_s.classify}CustomField".constantize.where(name: 'import_id')
if Fixnum === import_ids.first
existing = existing.where('cast(value as int) in (?)', import_ids)
else
existing = existing.where('value in (?)', import_ids)
end
existing = existing.where('value in (?)', import_ids.map(&:to_s))
if existing.count == import_ids.length
# puts "Skipping #{import_ids.length} already imported #{type}"

View File

@ -13,7 +13,7 @@ module ImportScripts::PhpBB3
# Executes a database query.
def query(sql)
@database_client.query(sql, cache_rows: false, symbolize_keys: true)
@database_client.query(sql, cache_rows: true, symbolize_keys: true)
end
# Executes a database query and returns the value of the 'count' column.

View File

@ -56,7 +56,7 @@ module ImportScripts::PhpBB3
rows = @database.fetch_users(offset)
break if rows.size < 1
next if all_records_exist? :users, importer.map_to_import_ids(rows)
next if all_records_exist?(:users, importer.map_users_to_import_ids(rows))
create_users(rows, total: total_count, offset: offset) do |row|
importer.map_user(row)
@ -73,6 +73,8 @@ module ImportScripts::PhpBB3
rows = @database.fetch_anonymous_users(offset)
break if rows.size < 1
next if all_records_exist?(:users, importer.map_anonymous_users_to_import_ids(rows))
create_users(rows, total: total_count, offset: offset) do |row|
importer.map_anonymous_user(row)
end
@ -98,6 +100,8 @@ module ImportScripts::PhpBB3
rows = @database.fetch_posts(offset)
break if rows.size < 1
next if all_records_exist?(:posts, importer.map_to_import_ids(rows))
create_posts(rows, total: total_count, offset: offset) do |row|
importer.map_post(row)
end
@ -118,6 +122,8 @@ module ImportScripts::PhpBB3
rows = @database.fetch_messages(@settings.fix_private_messages, offset)
break if rows.size < 1
next if all_records_exist?(:posts, importer.map_to_import_ids(rows))
create_posts(rows, total: total_count, offset: offset) do |row|
importer.map_message(row)
end

View File

@ -13,12 +13,17 @@ module ImportScripts::PhpBB3
@settings = settings
end
def map_to_import_ids(rows)
rows.map { |row| get_import_id(row) }
end
def map_message(row)
user_id = @lookup.user_id_from_imported_user_id(row[:author_id]) || Discourse.system_user.id
attachments = import_attachments(row, user_id)
mapped = {
id: "pm:#{row[:msg_id]}",
id: get_import_id(row),
user_id: user_id,
created_at: Time.zone.at(row[:message_time]),
raw: @text_processor.process_private_msg(row[:message_text], attachments)
@ -79,5 +84,9 @@ module ImportScripts::PhpBB3
import_user_id.to_s == author_id.to_s ? nil : @lookup.find_user_by_import_id(import_user_id).try(:username)
end.compact
end
def get_import_id(row)
"pm:#{row[:msg_id]}"
end
end
end

View File

@ -13,6 +13,10 @@ module ImportScripts::PhpBB3
@settings = settings
end
def map_to_import_ids(rows)
rows.map { |row| row[:post_id] }
end
def map_post(row)
imported_user_id = row[:post_username].blank? ? row[:poster_id] : row[:post_username]
user_id = @lookup.user_id_from_imported_user_id(imported_user_id) || Discourse.system_user.id

View File

@ -9,8 +9,8 @@ module ImportScripts::PhpBB3
@settings = settings
end
def map_to_import_ids(array)
array.map {|u| u[:user_id]}
def map_users_to_import_ids(rows)
rows.map { |row| row[:user_id] }
end
def map_user(row)
@ -42,6 +42,10 @@ module ImportScripts::PhpBB3
}
end
def map_anonymous_users_to_import_ids(rows)
rows.map { |row| row[:post_username] }
end
def map_anonymous_user(row)
username = row[:post_username]