From 44d673ffaaa9acbeeb79d46734fb15b3cba5fa6f Mon Sep 17 00:00:00 2001 From: saint Date: Sat, 17 Aug 2024 02:16:15 +1000 Subject: [PATCH] v0.39.3 Add SQLite table for tracking successful post importation; Split out user import into three separate callable methods; require sys/proctable --- gossamer_forums.rb | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/gossamer_forums.rb b/gossamer_forums.rb index 7c35bb4..820b8ea 100644 --- a/gossamer_forums.rb +++ b/gossamer_forums.rb @@ -1,7 +1,7 @@ # Federated Computer, Inc. # David Sainty 2024 A.D. # Gossamer Threads to Discourse -- Migration-Import Script -# v0.39.2 Add SQLite table for tracking successful post importation; Split out user import into three separate callable methods; require sys/proctable +# v0.39.3 Add SQLite table for tracking successful post importation; Split out user import into three separate callable methods; require sys/proctable require 'mysql2' require 'open-uri' @@ -604,6 +604,28 @@ class GossamerForumsImporter < ImportScripts::Base # Generate SQLite user ID mapping between Discourse and Gossamer def generate_user_id_mapping puts "Generating User ID Mapping..." + users = [] + + # Fetch all users from Gossamer Forums + execute_query("SELECT * FROM gforum_User").each do |row| + users << { + id: row['user_id'], + username: sanitize_username(row['user_username'], row['user_email'], row['user_real_name']), + email: row['user_email'], + created_at: Time.at(row['user_registered']), + updated_at: Time.at(row['user_last_seen']), + name: row['user_real_name'], + title: row['user_title'], + bio_raw: row['user_about'] || "", + website: row['user_homepage'], + location: row['user_location'], + custom_fields: { + md5_password: row['user_password'], + original_username: row['user_username'], + original_gossamer_id: row['user_id'] + } + } + end # For each user, add user ID mapping to SQLite now that we know what the Discourse user ID is users.each do |user| @@ -626,6 +648,27 @@ class GossamerForumsImporter < ImportScripts::Base # Import and set user Bio and Images def set_user_bio_images puts "Setting User Bio and Images..." + users = [] + + # Fetch all users from Gossamer Forums + execute_query("SELECT * FROM gforum_User").each do |row| + users << { + id: row['user_id'], + username: sanitize_username(row['user_username'], row['user_email'], row['user_real_name']), + email: row['user_email'], + created_at: Time.at(row['user_registered']), + updated_at: Time.at(row['user_last_seen']), + name: row['user_real_name'], + title: row['user_title'], + bio_raw: row['user_about'] || "", + website: row['user_homepage'], + location: row['user_location'], + md5_password: row['user_password'], + original_username: row['user_username'], + original_gossamer_id: row['user_id'] + } + } + end # For each user, append user bio and import user files users.each do |user|