From f00fa9d67d779550d0c1b399c84ef8d0b4741ce2 Mon Sep 17 00:00:00 2001 From: saint Date: Mon, 19 Aug 2024 20:00:59 +1000 Subject: [PATCH] v0.51 Fix mysql bug --- goss-cleanup.rb | 33 +++++++++++++++++++++++++++++++-- gossamer_forums.rb | 14 +++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/goss-cleanup.rb b/goss-cleanup.rb index 69c5ddf..8e4fdcf 100644 --- a/goss-cleanup.rb +++ b/goss-cleanup.rb @@ -47,6 +47,34 @@ class GossamerForumsCleaner end end + def cleanup_topics_former_user + puts "Cleaning up imported topics..." + + # Find all topics that were imported + TopicCustomField.where(name: 'original_gossamer_id').each do |field| + topic = Topic.find_by(id: field.topic_id) + + next unless topic + + # Fetch the first post in the topic + first_post = topic.posts.order(:created_at).first + + # Check if the first post has user_id 2 + if first_post && first_post.user_id == 2 + puts "Deleting topic #{topic.title} (ID: #{topic.id})" + + # Destroy all posts in the topic + topic.posts.each do |post| + puts "Deleting post #{post.id} in topic #{topic.id}" + post.destroy + end + + # Destroy the topic itself + topic.destroy + end + end + end + def cleanup_posts puts "Cleaning up imported posts..." # Find all posts that were imported and delete them @@ -102,8 +130,9 @@ class GossamerForumsCleaner def perform_cleanup puts "Cleanup beginning!" # cleanup_messages - cleanup_topics - cleanup_posts_parallel +# cleanup_topics + cleanup_topics_former_user +# cleanup_posts_parallel # cleanup_categories # cleanup_users puts "Cleanup complete!" diff --git a/gossamer_forums.rb b/gossamer_forums.rb index 632a4b9..0dec3f6 100644 --- a/gossamer_forums.rb +++ b/gossamer_forums.rb @@ -1281,13 +1281,13 @@ class GossamerForumsImporter < ImportScripts::Base # Fetch the mapped Discourse user and category ID based on Gossamer data discourse_user_id = fetch_user_id_mapping(row['user_id_fk']) - # Check to be certain user has not been deleted, etc. - if discourse_user_id.nil? || discourse_user_id == 0 - puts "discourse_user_id is NIL/ZERO for post_id #{row['post_id']}" - discourse_former_user = User.find_by(username: 'Former_User') - discourse_user_id = discourse_former_user.id - puts "discourse_user_id is NOW Former_User id #{discourse_user_id} for post_id #{row['post_id']}" - end +# # Check to be certain user has not been deleted, etc. +# if discourse_user_id.nil? || discourse_user_id == 0 +# puts "discourse_user_id is NIL/ZERO for post_id #{row['post_id']}" +# discourse_former_user = User.find_by(username: 'Former_User') +# discourse_user_id = discourse_former_user.id +# puts "discourse_user_id is NOW Former_User id #{discourse_user_id} for post_id #{row['post_id']}" +# end # Fetch the mapped Discourse user and category ID based on Gossamer data discourse_category_id = fetch_category_id_mapping(row['forum_id_fk'])