goss-cleanup 20240601-2

This commit is contained in:
dsainty 2024-06-17 19:43:33 +10:00
parent c481ddc8f0
commit 22526c4044

View File

@ -1,7 +1,7 @@
require File.expand_path("../../../config/environment", __FILE__)
class GossamerForumsCleaner
def perform_cleanup
def cleanup_users
puts "Cleaning up imported users..."
# Find all users imported from Gossamer Forums and delete them
UserCustomField.where(name: 'original_gossamer_id').each do |field|
@ -11,7 +11,9 @@ class GossamerForumsCleaner
user.destroy
end
end
end
def cleanup_categories
puts "Cleaning up imported categories..."
# Find all categories that were imported and delete them
CategoryCustomField.where(name: 'original_gossamer_id').each do |field|
@ -21,8 +23,10 @@ class GossamerForumsCleaner
category.destroy
end
end
end
puts "Cleaning up imported topics and posts..."
def cleanup_topics
puts "Cleaning up imported topics..."
# Find all topics that were imported and delete them
TopicCustomField.where(name: 'original_gossamer_id').each do |field|
topic = Topic.find_by(id: field.topic_id)
@ -35,7 +39,10 @@ class GossamerForumsCleaner
topic.destroy
end
end
end
def cleanup_posts
puts "Cleaning up imported posts..."
# Find all posts that were imported and delete them
PostCustomField.where(name: 'original_gossamer_id').each do |field|
post = Post.find_by(id: field.post_id)
@ -44,7 +51,9 @@ class GossamerForumsCleaner
post.destroy
end
end
end
def cleanup_messages
puts "Cleaning up imported personal messages..."
# Find all personal messages (inbox) that were imported and delete them
TopicCustomField.where(name: 'original_gossamer_msg_id').each do |field|
@ -58,20 +67,15 @@ class GossamerForumsCleaner
topic.destroy
end
end
end
# Find all sent personal messages that were imported and delete them
TopicCustomField.where(name: 'original_gossamer_sent_msg_id').each do |field|
topic = Topic.find_by(id: field.topic_id)
if topic
puts "Deleting sent personal message topic #{topic.title} (ID: #{topic.id})"
topic.posts.each do |post|
puts "Deleting post #{post.id} in sent personal message topic #{topic.id}"
post.destroy
end
topic.destroy
end
end
def perform_cleanup
puts "Cleanup beginning!"
# cleanup_messages
cleanup_posts
cleanup_topics
cleanup_categories
# cleanup_users
puts "Cleanup complete!"
end
end