goss-cleanup 20240531
This commit is contained in:
parent
0358a1cc0b
commit
8f63d8534d
80
goss-cleanup.rb
Normal file
80
goss-cleanup.rb
Normal file
@ -0,0 +1,80 @@
|
||||
require File.expand_path("../../../config/environment", __FILE__)
|
||||
|
||||
class GossamerForumsCleaner
|
||||
def perform_cleanup
|
||||
puts "Cleaning up imported users..."
|
||||
|
||||
# Find all users imported from Gossamer Forums and delete them
|
||||
UserCustomField.where(name: 'original_gossamer_id').each do |field|
|
||||
user = User.find_by(id: field.user_id)
|
||||
if user
|
||||
puts "Deleting user #{user.username} (ID: #{user.id})"
|
||||
user.destroy
|
||||
end
|
||||
end
|
||||
|
||||
puts "Cleaning up imported categories..."
|
||||
# Find all categories that were imported and delete them
|
||||
CategoryCustomField.where(name: 'original_gossamer_id').each do |field|
|
||||
category = Category.find_by(id: field.category_id)
|
||||
if category
|
||||
puts "Deleting category #{category.name} (ID: #{category.id})"
|
||||
category.destroy
|
||||
end
|
||||
end
|
||||
|
||||
puts "Cleaning up imported topics and posts..."
|
||||
# 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)
|
||||
if topic
|
||||
puts "Deleting topic #{topic.title} (ID: #{topic.id})"
|
||||
topic.posts.each do |post|
|
||||
puts "Deleting post #{post.id} in topic #{topic.id}"
|
||||
post.destroy
|
||||
end
|
||||
topic.destroy
|
||||
end
|
||||
end
|
||||
|
||||
# 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)
|
||||
if post
|
||||
puts "Deleting post #{post.id} (ID: #{post.id})"
|
||||
post.destroy
|
||||
end
|
||||
end
|
||||
|
||||
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|
|
||||
topic = Topic.find_by(id: field.topic_id)
|
||||
if topic
|
||||
puts "Deleting personal message topic #{topic.title} (ID: #{topic.id})"
|
||||
topic.posts.each do |post|
|
||||
puts "Deleting post #{post.id} in personal message topic #{topic.id}"
|
||||
post.destroy
|
||||
end
|
||||
topic.destroy
|
||||
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
|
||||
|
||||
puts "Cleanup complete!"
|
||||
end
|
||||
end
|
||||
|
||||
GossamerForumsCleaner.new.perform_cleanup
|
Loading…
Reference in New Issue
Block a user