v0.59 Final topic-post import run -- add logic for appending counts since we are adding to a live Discourse host now

This commit is contained in:
David Sainty 2024-09-02 16:27:07 +10:00
parent 7bd8f0068a
commit a39e435ffe
3 changed files with 35 additions and 20 deletions

BIN
.gossamer_forums.rb.swo Normal file

Binary file not shown.

Binary file not shown.

View File

@ -1572,7 +1572,7 @@ class GossamerForumsImporter < ImportScripts::Base
# next if post_id < highest_old_post_id
next if post_id <= highest_processed_post_id
puts "Processing post_id #{row['post_id']} post_id #{row['post_root_id']} post_subject/title #{row['post_subject']} forum_id_fk/category_id #{row['forum_id_fk']}"
puts "Processing post_id #{row['post_id']} post_root_id #{row['post_root_id']} post_subject/title #{row['post_subject']} forum_id_fk (category_id) #{row['forum_id_fk']}"
# discourse_user_id = @user_id_map[row['user_id_fk']]
# Fetch the Discourse user_id based on Gossamer data and mapping
@ -1731,13 +1731,15 @@ class GossamerForumsImporter < ImportScripts::Base
# Sanitize the post message
sanitized_post_message = sanitize_post_message(row['post_message'])
puts "CREATE REPLY in topic_id #{topic_id} for reply post_id #{row['post_id']}"
# topic_post_numbers[topic_id] += 1
post_number = fetch_db_topic_post_numbers(topic_id).to_i + 1
update_db_topic_post_numbers(topic_id, post_number)
puts "CREATE REPLY in topic_id #{topic_id} for reply post_id #{row['post_id']} with post_number #{post_number}"
# Create the post in the existing topic
post_created = false
while ! post_created
begin
post = Post.create!(
topic_id: topic_id,
user_id: discourse_user_id,
@ -1755,6 +1757,19 @@ class GossamerForumsImporter < ImportScripts::Base
post.custom_fields['original_gossamer_id'] = row['post_id']
post.save!
post_created = true
rescue ActiveRecord::RecordNotUnique => e
if e.message.include?("duplicate key value violates unique constraint")
post_number = post_number + 1
else
raise e
end
end
end
update_db_topic_post_numbers(topic_id, post_number)
# Track the number of posts in the topic and by the user
# topic_post_count[topic_id] += 1
# user_post_count[discourse_user_id] += 1