From 798d0947c470ae49196ed03a7e2b63d37a99c87d Mon Sep 17 00:00:00 2001 From: saint Date: Wed, 10 Jul 2024 14:12:38 +1000 Subject: [PATCH] v0.30 Add former_user support to prevent missing posts --- gossamer_forums.rb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/gossamer_forums.rb b/gossamer_forums.rb index cf4f2fc..7d0e5a4 100644 --- a/gossamer_forums.rb +++ b/gossamer_forums.rb @@ -1,5 +1,5 @@ # gossamer threads migration-import code -# v0.29 +# v0.30 require 'mysql2' require 'open-uri' @@ -490,6 +490,29 @@ class GossamerForumsImporter < ImportScripts::Base # upload # end + # Add 'Former_User' account if not already present + def add_former_user + puts "Adding 'Former User' account if it does not exist..." + + former_user = User.find_by(username: 'Former_User') + + if former_user.nil? + former_user = User.create!( + username: 'Former_User', + name: 'Former User', + email: 'former_user@example.com', + password: SecureRandom.hex(16), + active: true + ) + puts "'Former User' account created with user ID: #{former_user.id}" + + # Store the user ID mapping + puts "for insert_user_id_mapping: 0 (former_user) discourse_user.id #{former_user.id}" + insert_user_id_mapping(0, former_user.id) + else + puts "'Former User' account already exists with user ID: #{former_user.id}" + end + end # Import users from Gossamer Forums to Discourse def import_users @@ -893,7 +916,7 @@ class GossamerForumsImporter < ImportScripts::Base execute_query("SELECT * FROM gforum_Post ORDER BY post_id").each do |row| post_id = row['post_id'].to_i - # Skip posts that have already been processed + # Skip posts that have already been processed # FIXED PROPERLY FOR FUTURE RUNS # next if post_id < highest_old_post_id next if post_id <= highest_processed_post_id @@ -1249,6 +1272,7 @@ class GossamerForumsImporter < ImportScripts::Base puts "Starting Gossamer Forums import... #{timestamp}" + add_former_user # import_users # export_username_mapping_to_csv("gossamer-migration-username-mapping#{timestamp}")