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