Improve phpBB3 importer

Improve phpBB3 importer

  • Log errors when mapping of posts, messages, etc. fails
  • Allow permalink normalizations for old subfolder installation
  • Disable importing of polls for now. It’s broken.
diff --git a/script/import_scripts/phpbb3/importer.rb b/script/import_scripts/phpbb3/importer.rb
index 8ed128d..a7142e0 100644
--- a/script/import_scripts/phpbb3/importer.rb
+++ b/script/import_scripts/phpbb3/importer.rb
@@ -70,7 +70,11 @@ module ImportScripts::PhpBB3
         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)
+          begin
+            importer.map_user(row)
+          rescue => e
+            log_error("Failed to map user with ID #{row[:user_id]}", e)
+          end
         end
       end
     end
@@ -88,7 +92,11 @@ module ImportScripts::PhpBB3
         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)
+          begin
+            importer.map_anonymous_user(row)
+          rescue => e
+            log_error("Failed to map anonymous user with ID #{row[:user_id]}", e)
+          end
         end
       end
     end
@@ -116,7 +124,11 @@ module ImportScripts::PhpBB3
         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)
+          begin
+            importer.map_post(row)
+          rescue => e
+            log_error("Failed to map post with ID #{row[:post_id]}", e)
+          end
         end
       end
     end
@@ -134,7 +146,11 @@ module ImportScripts::PhpBB3
         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)
+          begin
+            importer.map_message(row)
+          rescue => e
+            log_error("Failed to map message with ID #{row[:msg_id]}", e)
+          end
         end
       end
     end
@@ -167,5 +183,11 @@ module ImportScripts::PhpBB3
     def batches
       super(@settings.database.batch_size)
     end
+
+    def log_error(message, e)
+      puts message
+      puts e.message
+      puts e.backtrace.join("\n")
+    end
   end
 end
diff --git a/script/import_scripts/phpbb3/importers/permalink_importer.rb b/script/import_scripts/phpbb3/importers/permalink_importer.rb
index 140a160..5d79ab5 100644
--- a/script/import_scripts/phpbb3/importers/permalink_importer.rb
+++ b/script/import_scripts/phpbb3/importers/permalink_importer.rb
@@ -47,6 +47,11 @@ module ImportScripts::PhpBB3
     protected
 
     def add_normalization(normalizations, normalization)
+      if @settings.normalization_prefix.present?
+        prefix = @settings.normalization_prefix[%r|^/?(.*?)/?$|, 1]
+        normalization = "/#{prefix.gsub('/', '\/')}\\#{normalization}"
+      end
+
       normalizations << normalization unless normalizations.include?(normalization)
     end
 
diff --git a/script/import_scripts/phpbb3/settings.yml b/script/import_scripts/phpbb3/settings.yml
index 08b50e2..9a4b6a9 100644
--- a/script/import_scripts/phpbb3/settings.yml
+++ b/script/import_scripts/phpbb3/settings.yml
@@ -31,6 +31,9 @@ import:
     categories: true  # redirects   /viewforum.php?f=1            to  /c/category-name
     topics: true      # redirects   /viewtopic.php?f=6&t=43       to  /t/topic-name/81
     posts: false      # redirects   /viewtopic.php?p=2455#p2455   to  /t/topic-name/81/4
+    # Append a prefix to each type of link, e.g. 'forum' to redirect /forum/viewtopic.php?f=6&t=43 to /t/topic-name/81
+    # Leave it empty if your forum wasn't installed in a subfolder.
+    prefix:
 
   avatars:
     uploaded: true  # import uploaded avatars
@@ -50,7 +53,7 @@ import:
   bookmarks: true
   attachments: true
   private_messages: true
-  polls: true
+  polls: false  # Don't set this to true. Importing polls is currently broken.
 
   # When true: each imported user will have the original username from phpBB as its name
   # When false: the name of each imported user will be blank unless the username was changed during import
diff --git a/script/import_scripts/phpbb3/support/settings.rb b/script/import_scripts/phpbb3/support/settings.rb
index 9c63e2a..0fdafdf 100644
--- a/script/import_scripts/phpbb3/support/settings.rb
+++ b/script/import_scripts/phpbb3/support/settings.rb
@@ -84,11 +84,13 @@ module ImportScripts::PhpBB3
     attr_reader :create_category_links
     attr_reader :create_topic_links
     attr_reader :create_post_links
+    attr_reader :normalization_prefix
 
     def initialize(yaml)
       @create_category_links = yaml['categories']
       @create_topic_links = yaml['topics']
       @create_post_links = yaml['posts']
+      @normalization_prefix = yaml['prefix']
     end
   end
 end

GitHub sha: 24369a81

Does this mean we need a followup here?

1 Like

There’s a simple workaround: Import on 2.1 and upgrade later. I have a partial fix from my time working on adding support for phpBB 3.2, but my vacation was over before I had time to finish it. It’s sitting in a branch of mine for the time being. No need for a follow-up IMHO. I won’t forget fixing it.

1 Like

FIX: Importing of polls from phpBB3 was broken