v0.5 We need to handle deletion of topic posts -- delete all posts in topic and then delete topic itself

This commit is contained in:
David Sainty 2024-09-09 15:15:58 +10:00
parent 393cea00c2
commit 78b4613570

View File

@ -1,7 +1,7 @@
# Federated Computer, Inc.
# David Sainty <saint@federated.computer> 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'
@ -43,6 +43,25 @@ class GossamerForumsDestroyDeletedPosts < ImportScripts::Base
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,11 +84,21 @@ class GossamerForumsDestroyDeletedPosts < ImportScripts::Base
post = find_post_by_custom_field(post_id)
if post
puts "DestroyDeletedPosts: Mock-Deleting post with id: #{post.id}"
# 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
def perform_deleted_destroy
puts "Destroy Deleted Posts beginning!"