diff --git a/script/import_scripts/phpbb3/database/database_base.rb b/script/import_scripts/phpbb3/database/database_base.rb index 3c8b4b371..a63cecf4c 100644 --- a/script/import_scripts/phpbb3/database/database_base.rb +++ b/script/import_scripts/phpbb3/database/database_base.rb @@ -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. diff --git a/script/import_scripts/phpbb3/importer.rb b/script/import_scripts/phpbb3/importer.rb index 11592b40d..f2c1dc9de 100644 --- a/script/import_scripts/phpbb3/importer.rb +++ b/script/import_scripts/phpbb3/importer.rb @@ -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 diff --git a/script/import_scripts/phpbb3/importers/message_importer.rb b/script/import_scripts/phpbb3/importers/message_importer.rb index 6200b0b02..0ebab7d24 100644 --- a/script/import_scripts/phpbb3/importers/message_importer.rb +++ b/script/import_scripts/phpbb3/importers/message_importer.rb @@ -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 diff --git a/script/import_scripts/phpbb3/importers/post_importer.rb b/script/import_scripts/phpbb3/importers/post_importer.rb index be0daebbf..b6de98622 100644 --- a/script/import_scripts/phpbb3/importers/post_importer.rb +++ b/script/import_scripts/phpbb3/importers/post_importer.rb @@ -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 diff --git a/script/import_scripts/phpbb3/importers/user_importer.rb b/script/import_scripts/phpbb3/importers/user_importer.rb index aeef5ec86..c1cd91499 100644 --- a/script/import_scripts/phpbb3/importers/user_importer.rb +++ b/script/import_scripts/phpbb3/importers/user_importer.rb @@ -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]