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_old_post_id
next if post_id <= highest_processed_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']] # discourse_user_id = @user_id_map[row['user_id_fk']]
# Fetch the Discourse user_id based on Gossamer data and mapping # Fetch the Discourse user_id based on Gossamer data and mapping
@ -1731,29 +1731,44 @@ class GossamerForumsImporter < ImportScripts::Base
# Sanitize the post message # Sanitize the post message
sanitized_post_message = sanitize_post_message(row['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 # topic_post_numbers[topic_id] += 1
post_number = fetch_db_topic_post_numbers(topic_id).to_i + 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 # Create the post in the existing topic
post = Post.create!( post_created = false
topic_id: topic_id, while ! post_created
user_id: discourse_user_id, begin
raw: sanitized_post_message, post = Post.create!(
created_at: Time.at(row['post_time']), topic_id: topic_id,
updated_at: Time.at(row['post_time']), user_id: discourse_user_id,
reads: post_views || 0, raw: sanitized_post_message,
post_number: post_number created_at: Time.at(row['post_time']),
) updated_at: Time.at(row['post_time']),
# raw: import_attachments(row['post_message'], row['post_id']), reads: post_views || 0,
# raw: row['post_message'] || "", post_number: post_number
# reply_to_post_number: reply_to_post_number, )
# like_count: row['post_replies'] || 0, # raw: import_attachments(row['post_message'], row['post_id']),
# reads: post_views || fetch_db_topic_post_count(topic_id).to_i, # raw: row['post_message'] || "",
post.custom_fields['original_gossamer_id'] = row['post_id'] # reply_to_post_number: reply_to_post_number,
post.save! # like_count: row['post_replies'] || 0,
# reads: post_views || fetch_db_topic_post_count(topic_id).to_i,
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 # Track the number of posts in the topic and by the user
# topic_post_count[topic_id] += 1 # topic_post_count[topic_id] += 1