Merge pull request #3823 from gschlager/phpbb3-importer
FIX: phpBB3 importer failed to import users
This commit is contained in:
commit
91fdfa986f
|
@ -198,12 +198,7 @@ class ImportScripts::Base
|
||||||
return false if import_ids.empty?
|
return false if import_ids.empty?
|
||||||
|
|
||||||
existing = "#{type.to_s.classify}CustomField".constantize.where(name: 'import_id')
|
existing = "#{type.to_s.classify}CustomField".constantize.where(name: 'import_id')
|
||||||
|
existing = existing.where('value in (?)', import_ids.map(&:to_s))
|
||||||
if Fixnum === import_ids.first
|
|
||||||
existing = existing.where('cast(value as int) in (?)', import_ids)
|
|
||||||
else
|
|
||||||
existing = existing.where('value in (?)', import_ids)
|
|
||||||
end
|
|
||||||
|
|
||||||
if existing.count == import_ids.length
|
if existing.count == import_ids.length
|
||||||
# puts "Skipping #{import_ids.length} already imported #{type}"
|
# puts "Skipping #{import_ids.length} already imported #{type}"
|
||||||
|
|
|
@ -13,7 +13,7 @@ module ImportScripts::PhpBB3
|
||||||
|
|
||||||
# Executes a database query.
|
# Executes a database query.
|
||||||
def query(sql)
|
def query(sql)
|
||||||
@database_client.query(sql, cache_rows: false, symbolize_keys: true)
|
@database_client.query(sql, cache_rows: true, symbolize_keys: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Executes a database query and returns the value of the 'count' column.
|
# Executes a database query and returns the value of the 'count' column.
|
||||||
|
|
|
@ -56,7 +56,7 @@ module ImportScripts::PhpBB3
|
||||||
rows = @database.fetch_users(offset)
|
rows = @database.fetch_users(offset)
|
||||||
break if rows.size < 1
|
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|
|
create_users(rows, total: total_count, offset: offset) do |row|
|
||||||
importer.map_user(row)
|
importer.map_user(row)
|
||||||
|
@ -73,6 +73,8 @@ module ImportScripts::PhpBB3
|
||||||
rows = @database.fetch_anonymous_users(offset)
|
rows = @database.fetch_anonymous_users(offset)
|
||||||
break if rows.size < 1
|
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|
|
create_users(rows, total: total_count, offset: offset) do |row|
|
||||||
importer.map_anonymous_user(row)
|
importer.map_anonymous_user(row)
|
||||||
end
|
end
|
||||||
|
@ -98,6 +100,8 @@ module ImportScripts::PhpBB3
|
||||||
rows = @database.fetch_posts(offset)
|
rows = @database.fetch_posts(offset)
|
||||||
break if rows.size < 1
|
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|
|
create_posts(rows, total: total_count, offset: offset) do |row|
|
||||||
importer.map_post(row)
|
importer.map_post(row)
|
||||||
end
|
end
|
||||||
|
@ -118,6 +122,8 @@ module ImportScripts::PhpBB3
|
||||||
rows = @database.fetch_messages(@settings.fix_private_messages, offset)
|
rows = @database.fetch_messages(@settings.fix_private_messages, offset)
|
||||||
break if rows.size < 1
|
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|
|
create_posts(rows, total: total_count, offset: offset) do |row|
|
||||||
importer.map_message(row)
|
importer.map_message(row)
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,12 +13,17 @@ module ImportScripts::PhpBB3
|
||||||
@settings = settings
|
@settings = settings
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def map_to_import_ids(rows)
|
||||||
|
rows.map { |row| get_import_id(row) }
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def map_message(row)
|
def map_message(row)
|
||||||
user_id = @lookup.user_id_from_imported_user_id(row[:author_id]) || Discourse.system_user.id
|
user_id = @lookup.user_id_from_imported_user_id(row[:author_id]) || Discourse.system_user.id
|
||||||
attachments = import_attachments(row, user_id)
|
attachments = import_attachments(row, user_id)
|
||||||
|
|
||||||
mapped = {
|
mapped = {
|
||||||
id: "pm:#{row[:msg_id]}",
|
id: get_import_id(row),
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
created_at: Time.zone.at(row[:message_time]),
|
created_at: Time.zone.at(row[:message_time]),
|
||||||
raw: @text_processor.process_private_msg(row[:message_text], attachments)
|
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)
|
import_user_id.to_s == author_id.to_s ? nil : @lookup.find_user_by_import_id(import_user_id).try(:username)
|
||||||
end.compact
|
end.compact
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_import_id(row)
|
||||||
|
"pm:#{row[:msg_id]}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,6 +13,10 @@ module ImportScripts::PhpBB3
|
||||||
@settings = settings
|
@settings = settings
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def map_to_import_ids(rows)
|
||||||
|
rows.map { |row| row[:post_id] }
|
||||||
|
end
|
||||||
|
|
||||||
def map_post(row)
|
def map_post(row)
|
||||||
imported_user_id = row[:post_username].blank? ? row[:poster_id] : row[:post_username]
|
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
|
user_id = @lookup.user_id_from_imported_user_id(imported_user_id) || Discourse.system_user.id
|
||||||
|
|
|
@ -9,8 +9,8 @@ module ImportScripts::PhpBB3
|
||||||
@settings = settings
|
@settings = settings
|
||||||
end
|
end
|
||||||
|
|
||||||
def map_to_import_ids(array)
|
def map_users_to_import_ids(rows)
|
||||||
array.map {|u| u[:user_id]}
|
rows.map { |row| row[:user_id] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def map_user(row)
|
def map_user(row)
|
||||||
|
@ -42,6 +42,10 @@ module ImportScripts::PhpBB3
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def map_anonymous_users_to_import_ids(rows)
|
||||||
|
rows.map { |row| row[:post_username] }
|
||||||
|
end
|
||||||
|
|
||||||
def map_anonymous_user(row)
|
def map_anonymous_user(row)
|
||||||
username = row[:post_username]
|
username = row[:post_username]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue