diff --git a/.gossamer_forums.rb.swo b/.gossamer_forums.rb.swo new file mode 100644 index 0000000..29d15f2 Binary files /dev/null and b/.gossamer_forums.rb.swo differ diff --git a/.nfs0000000000163a0500000006 b/.nfs0000000000163a0500000006 deleted file mode 100644 index 0501b92..0000000 Binary files a/.nfs0000000000163a0500000006 and /dev/null differ diff --git a/gossamer_forums.rb b/gossamer_forums.rb index 9d6df1d..8356f70 100644 --- a/gossamer_forums.rb +++ b/gossamer_forums.rb @@ -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,29 +1731,44 @@ 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 = Post.create!( - topic_id: topic_id, - user_id: discourse_user_id, - raw: sanitized_post_message, - created_at: Time.at(row['post_time']), - updated_at: Time.at(row['post_time']), - reads: post_views || 0, - post_number: post_number - ) -# raw: import_attachments(row['post_message'], row['post_id']), -# raw: row['post_message'] || "", -# reply_to_post_number: reply_to_post_number, -# 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 = false + while ! post_created + begin + post = Post.create!( + topic_id: topic_id, + user_id: discourse_user_id, + raw: sanitized_post_message, + created_at: Time.at(row['post_time']), + updated_at: Time.at(row['post_time']), + reads: post_views || 0, + post_number: post_number + ) +# raw: import_attachments(row['post_message'], row['post_id']), +# raw: row['post_message'] || "", +# reply_to_post_number: reply_to_post_number, +# 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 # topic_post_count[topic_id] += 1