From 78b461357083012edc3db3dc0ec5bd823dad5b46 Mon Sep 17 00:00:00 2001 From: saint Date: Mon, 9 Sep 2024 15:15:58 +1000 Subject: [PATCH] v0.5 We need to handle deletion of topic posts -- delete all posts in topic and then delete topic itself --- goss-destroydeletedposts.rb | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/goss-destroydeletedposts.rb b/goss-destroydeletedposts.rb index 423a0fc..e11d765 100644 --- a/goss-destroydeletedposts.rb +++ b/goss-destroydeletedposts.rb @@ -1,7 +1,7 @@ # Federated Computer, Inc. # David Sainty 2024 A.D. # Gossamer Threads to Discourse -- CleanUp Script -# v0.4 Go back to simpler use of MySQL2 +# v0.5 We need to handle deletion of topic posts -- delete all posts in topic and then delete topic itself require 'mysql2' require 'active_record' @@ -42,7 +42,26 @@ class GossamerForumsDestroyDeletedPosts < ImportScripts::Base nil end end - + + # Define a method to delete all posts in a topic + def delete_all_posts_in_topic(topic_id) + posts = Post.where(topic_id: topic_id) + posts.each do |post| + puts "DELETE ALL POSTS --- DiscourseDeletedPosts: Deleting post with id: #{post.id}" + # post.destroy + end + end + + # Define a method to delete a topic + def delete_topic(topic_id) + topic = Topic.find_by(id: topic_id) + if topic + puts "DELETE TOPIC --- DiscourseDeletedPosts: Deleting topic with id: #{topic_id}" + # topic.destroy + end + end + + # Define the method to delete posts based on the Gossamer Forums flag def destroy_deleted_posts_from_gossamer_with_user(username) @@ -65,8 +84,18 @@ class GossamerForumsDestroyDeletedPosts < ImportScripts::Base post = find_post_by_custom_field(post_id) if post - puts "DestroyDeletedPosts: Mock-Deleting post with id: #{post.id}" - # post.destroy + # Check if this post is the topic post + if post.post_number == 1 + topic_id = post.topic_id + # Delete all posts in the topic + delete_all_posts_in_topic(topic_id) + # Delete the topic itself + delete_topic(topic_id) + else + # If not the topic post, just delete the individual post + puts "DELETE POST --- DestroyDeletedPosts: Deleting post with id: #{post.id}" + # post.destroy + end end end end