v0.57 Improve personal message handling and add commented line for doing specified blocks of PMs.

This commit is contained in:
David Sainty 2024-08-30 15:28:53 +10:00
parent b0b7996af1
commit ea15d4b6e2

View File

@ -1,7 +1,7 @@
# Federated Computer, Inc. # Federated Computer, Inc.
# David Sainty <saint@federated.computer> 2024 A.D. # David Sainty <saint@federated.computer> 2024 A.D.
# Gossamer Threads to Discourse -- Migration-Import Script # 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 'mysql2'
require 'open-uri' require 'open-uri'
@ -1856,7 +1856,7 @@ class GossamerForumsImporter < ImportScripts::Base
highest_processed_personal_id = fetch_highest_processed_personal_id.to_i highest_processed_personal_id = fetch_highest_processed_personal_id.to_i
puts "Highest processed personal_id: #{highest_processed_personal_id}" 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 # # # highest_processed_personal_id = 1543840
puts "Highest processed personal_id override: #{highest_processed_personal_id}" puts "Highest processed personal_id override: #{highest_processed_personal_id}"
@ -1866,6 +1866,8 @@ class GossamerForumsImporter < ImportScripts::Base
puts "msg_id #{msg_id}" puts "msg_id #{msg_id}"
# Skip posts that have already been processed # 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 next if msg_id <= highest_processed_personal_id
from_user_id = fetch_user_id_mapping(row['from_user_id_fk']) 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 # Update the topic's last reply information
topic.update!( topic.update!(
last_posted_at: post.updated_at, 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) update_highest_processed_personal_id(msg_id)
@ -1963,6 +1966,26 @@ class GossamerForumsImporter < ImportScripts::Base
end end
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 # Main method to perform the import
def perform_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_url_mapping_to_csv("/bitnami/discourse/sqlite/gossamer-migration-url-mapping#{timestamp}")
# export_nginx_rewrite_rules("/bitnami/discourse/sqlite/gossamer-redirects#{timestamp}.conf") # export_nginx_rewrite_rules("/bitnami/discourse/sqlite/gossamer-redirects#{timestamp}.conf")
update_existing_personal_message_activity
import_personal_messages import_personal_messages
puts "Gossamer Forums import complete! #{timestamp}" puts "Gossamer Forums import complete! #{timestamp}"