v0.29 Final tweak for personal msg import for now; prep for migration cont
This commit is contained in:
parent
515e1c55c2
commit
1223421028
@ -1,5 +1,5 @@
|
|||||||
# gossamer threads migration-import code
|
# gossamer threads migration-import code
|
||||||
# v0.28.1
|
# v0.29
|
||||||
|
|
||||||
require 'mysql2'
|
require 'mysql2'
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
@ -1160,75 +1160,79 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
|
|
||||||
# Import personal messages from gforum_Message table (both inbox and sent messages)
|
# Import personal messages from gforum_Message table (both inbox and sent messages)
|
||||||
def import_personal_messages
|
def import_personal_messages
|
||||||
puts "Importing personal (inbox and sendmail) messages..."
|
puts "Importing personal (inbox and sentmail) messages..."
|
||||||
|
|
||||||
# Fetch the highest_processed_personal_id
|
# Fetch the highest_processed_personal_id
|
||||||
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 get to problem msg
|
# OVERRIDE - to speed getting to problem msg
|
||||||
highest_processed_personal_id = 350
|
# highest_processed_personal_id = 350
|
||||||
puts "Highest processed personal_id override: #{highest_processed_personal_id}"
|
puts "Highest processed personal_id override: #{highest_processed_personal_id}"
|
||||||
|
|
||||||
execute_query("SELECT * FROM gforum_Message").each do |row|
|
execute_query("SELECT * FROM gforum_Message").each do |row|
|
||||||
msg_id = row['msg_id'].to_i
|
begin
|
||||||
puts "msg_id #{msg_id}"
|
msg_id = row['msg_id'].to_i
|
||||||
|
puts "msg_id #{msg_id}"
|
||||||
|
|
||||||
# Skip posts that have already been processed
|
# Skip posts that have already been processed
|
||||||
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'])
|
||||||
to_user_id = fetch_user_id_mapping(row['to_user_id_fk'])
|
to_user_id = fetch_user_id_mapping(row['to_user_id_fk'])
|
||||||
|
|
||||||
next unless from_user_id && to_user_id
|
next unless from_user_id && to_user_id
|
||||||
|
|
||||||
# Skip if the message already exists
|
# Skip if the message already exists
|
||||||
unless TopicCustomField.exists?(name: 'original_gossamer_msg_id', value: row['msg_id'])
|
unless TopicCustomField.exists?(name: 'original_gossamer_msg_id', value: row['msg_id'])
|
||||||
|
|
||||||
# Sanitize the message, ensuring we have an empty string or the content without any \0
|
# Sanitize the message, ensuring we have an empty string or the content without any \0
|
||||||
sanitized_message = sanitize_post_message(row['msg_body'])
|
sanitized_message = sanitize_post_message(row['msg_body'])
|
||||||
|
|
||||||
# Set default message body if the sanitized message is blank
|
# Set default message body if the sanitized message is blank
|
||||||
sanitized_message = "<no message body>" if sanitized_message.strip.empty?
|
sanitized_message = "<No message body to migrate.>" if sanitized_message.strip.empty? || sanitized_message.split.size < 3
|
||||||
|
|
||||||
# If we do not change the "min personal message post length" to 1, we need this. ... We may need this anyway.
|
# If we do not change the "min personal message post length" to 1, we need this. ... We may need this anyway.
|
||||||
sanitized_message = sanitized_message.ljust(10, '.') if sanitized_message.length < 10
|
sanitized_message = sanitized_message.ljust(10, '.') if sanitized_message.length < 10
|
||||||
|
|
||||||
# Check and set a default title if the original title is nil or empty
|
# Check and set a default title if the original title is nil or empty
|
||||||
sanitized_title = row['msg_subject']&.strip
|
sanitized_title = row['msg_subject']&.strip
|
||||||
sanitized_title = "<no subject>" if sanitized_title.nil? || sanitized_title.empty?
|
sanitized_title = "<no subject>" if sanitized_title.nil? || sanitized_title.empty?
|
||||||
|
|
||||||
puts "IMPORTING msg. sanitized_title: #{sanitized_title} orig title: #{row['msg_subject']} user_id #{from_user_id} to_user_id #{to_user_id}"
|
puts "IMPORTING msg. sanitized: #{sanitized_title} user_id #{from_user_id} to_user_id #{to_user_id}"
|
||||||
|
|
||||||
# Create a private message topic in Discourse
|
# Create a private message topic in Discourse
|
||||||
topic = Topic.create!(
|
topic = Topic.create!(
|
||||||
title: sanitized_title,
|
title: sanitized_title,
|
||||||
user_id: from_user_id,
|
user_id: from_user_id,
|
||||||
archetype: Archetype.private_message,
|
archetype: Archetype.private_message,
|
||||||
created_at: Time.at(row['msg_time']),
|
created_at: Time.at(row['msg_time']),
|
||||||
updated_at: Time.at(row['msg_time'])
|
updated_at: Time.at(row['msg_time'])
|
||||||
)
|
)
|
||||||
topic.custom_fields['original_gossamer_msg_id'] = row['msg_id']
|
topic.custom_fields['original_gossamer_msg_id'] = row['msg_id']
|
||||||
topic.save!
|
topic.save!
|
||||||
|
|
||||||
# Create the message as a post in the private topic
|
# Create the message as a post in the private topic
|
||||||
post = Post.create!(
|
post = Post.create!(
|
||||||
topic_id: topic.id,
|
topic_id: topic.id,
|
||||||
user_id: from_user_id,
|
user_id: from_user_id,
|
||||||
raw: sanitized_message,
|
raw: sanitized_message,
|
||||||
created_at: Time.at(row['msg_time']),
|
created_at: Time.at(row['msg_time']),
|
||||||
updated_at: Time.at(row['msg_time'])
|
updated_at: Time.at(row['msg_time'])
|
||||||
)
|
)
|
||||||
post.custom_fields['original_gossamer_msg_id'] = row['msg_id']
|
post.custom_fields['original_gossamer_msg_id'] = row['msg_id']
|
||||||
post.save!
|
post.save!
|
||||||
|
|
||||||
# Add recipient user to the private message topic
|
# Add recipient user to the private message topic
|
||||||
topic.topic_allowed_users.create!(user_id: to_user_id)
|
topic.topic_allowed_users.create!(user_id: to_user_id)
|
||||||
|
|
||||||
update_highest_processed_personal_id(msg_id)
|
update_highest_processed_personal_id(msg_id)
|
||||||
|
|
||||||
# N/A. These were never a thing in Slowtwitch...
|
# N/A. These were never a thing in Slowtwitch...
|
||||||
# handle_post_attachments(row['msg_id'], post, from_user_id)
|
# handle_post_attachments(row['msg_id'], post, from_user_id)
|
||||||
|
end
|
||||||
|
rescue StandardError => e
|
||||||
|
puts "Error importing message #{row['msg_id']}: #{e.message}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1250,11 +1254,11 @@ class GossamerForumsImporter < ImportScripts::Base
|
|||||||
|
|
||||||
# import_categories
|
# import_categories
|
||||||
|
|
||||||
# import_topics_and_posts_with_attachments
|
import_topics_and_posts_with_attachments
|
||||||
# update_topic_stats
|
update_topic_stats
|
||||||
update_user_stats
|
update_user_stats
|
||||||
# export_url_mapping_to_csv("gossamer-migration-url-mapping#{timestamp}")
|
export_url_mapping_to_csv("gossamer-migration-url-mapping#{timestamp}")
|
||||||
# create_nginx_rewrite_rules("gossamer-redirects#{timestamp}.conf")
|
create_nginx_rewrite_rules("gossamer-redirects#{timestamp}.conf")
|
||||||
|
|
||||||
import_personal_messages
|
import_personal_messages
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user