From e6f7d313ac03f998104b581f6174fb3d2b3950af Mon Sep 17 00:00:00 2001 From: saint Date: Thu, 29 Aug 2024 20:52:55 +1000 Subject: [PATCH] Auxiliary script changes for testing in Prod 20240829 --- goss-cleanup.rb | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/goss-cleanup.rb b/goss-cleanup.rb index 7bdd75a..d0fdea5 100644 --- a/goss-cleanup.rb +++ b/goss-cleanup.rb @@ -77,29 +77,19 @@ class GossamerForumsCleaner def cleanup_topics_with_invalid_posts_count puts "Cleaning up topics with invalid posts_count..." + + # Iterate through all topics + Topic.where("posts_count IS NULL OR posts_count = -1").find_each do |topic| + puts "Identified topic for deletion: Title: #{topic.title} Topic ID: #{topic.id}" - # 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 - - # Check if the posts_count is nil or -1 - if topic.posts_count.nil? || topic.posts_count == -1 - # first_post = topic.posts.order(:created_at).first - # user_name = first_post&.user&.username || 'Unknown' - - puts "Identified topic for deletion: Title: #{topic.title} Topic 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 + # 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