From ea15d4b6e2e4a33132c29204ed627cc376403f11 Mon Sep 17 00:00:00 2001 From: saint Date: Fri, 30 Aug 2024 15:28:53 +1000 Subject: [PATCH] v0.57 Improve personal message handling and add commented line for doing specified blocks of PMs. --- gossamer_forums.rb | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/gossamer_forums.rb b/gossamer_forums.rb index f6569b1..33b3b5f 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.56 Prep to run 20240828 MDT +# v0.57 Improve personal message handling and add commented line for doing specified blocks of PMs. require 'mysql2' require 'open-uri' @@ -1856,7 +1856,7 @@ class GossamerForumsImporter < ImportScripts::Base highest_processed_personal_id = fetch_highest_processed_personal_id.to_i puts "Highest processed personal_id: #{highest_processed_personal_id}" -# OVERRIDE - to speed getting to problem msg +# OVERRIDE - to speed getting to lower limit msg # # # highest_processed_personal_id = 1543840 puts "Highest processed personal_id override: #{highest_processed_personal_id}" @@ -1866,6 +1866,8 @@ class GossamerForumsImporter < ImportScripts::Base puts "msg_id #{msg_id}" # Skip posts that have already been processed +# OVERRIDE - upper limit msg +# # # next if msg_id <= highest_processed_personal_id || msg_id > 342443 next if msg_id <= highest_processed_personal_id from_user_id = fetch_user_id_mapping(row['from_user_id_fk']) @@ -1949,7 +1951,8 @@ class GossamerForumsImporter < ImportScripts::Base # Update the topic's last reply information topic.update!( last_posted_at: post.updated_at, - last_post_user_id: post.user_id + last_post_user_id: post.user_id, + bumped_at: post.updated_at ) update_highest_processed_personal_id(msg_id) @@ -1963,6 +1966,26 @@ class GossamerForumsImporter < ImportScripts::Base end end + def update_existing_personal_message_activity + puts "Updating Activity field for existing private / personal message topics..." + + private_message_topics = Topic.where(archetype: Archetype.private_message) + + private_message_topics.each do |topic| + last_post = topic.posts.order(updated_at: :desc).first + + if last_post + topic.update_columns( + last_posted_at: last_post.updated_at, + last_post_user_id: last_post.user_id, + bumped_at: last_post.updated_at + ) + puts "Updated topic ID #{topic.id} with last activity at #{last_post.updated_at}" + else + puts "No posts found for topic ID #{topic.id}; skipping update." + end + end + end # Main method to perform the import def perform_import @@ -2012,6 +2035,7 @@ class GossamerForumsImporter < ImportScripts::Base # export_url_mapping_to_csv("/bitnami/discourse/sqlite/gossamer-migration-url-mapping#{timestamp}") # export_nginx_rewrite_rules("/bitnami/discourse/sqlite/gossamer-redirects#{timestamp}.conf") + update_existing_personal_message_activity import_personal_messages puts "Gossamer Forums import complete! #{timestamp}"