Created
March 23, 2015 02:13
-
-
Save gnunicorn/2ad36034c5c9c9d11187 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NEW_SERVER = "http://community.hackership.org" | |
def find_all_cats(category_id) | |
Category.where(:parent_category_id => category_id).pluck(:id) << category_id | |
end | |
def replace_topic_with_permalink(topic) | |
current = topic.relative_url | |
Permalink.new(:url => current, :external_url => "#{NEW_SERVER}#{current}").save | |
topic.destroy | |
end | |
def soft_cleanup(category) | |
Category.where(:parent_category_id => category.id).each do |category| | |
puts "cleaning" | |
puts category.name | |
puts "topuc destroyed" | |
puts Topic.where(:category_id => category.id).destroy_all.length | |
category.destroy | |
end | |
puts "final cleasing" | |
puts Topic.where(:category_id => category.id).destroy_all.length | |
end | |
def hard_destroy_category(cats) | |
puts "destroyed topics: " | |
puts Topic.where("category_id in (?)", cats).destroy_all.length | |
puts "destroyed categories: " | |
puts Category.where("id in (?)", cats).destroy_all.length | |
end | |
def hard_clean_up(keepers) | |
return false if !keepers | |
keepers += ['meta', 'uncategorized', 'lounge', 'staff'] | |
Category.where(:parent_category_id => nil).where("slug not in (?)", keepers).each do |category| | |
puts "deleting" | |
puts category.name | |
hard_destroy_category(find_all_cats (category.id)) | |
end | |
puts "done" | |
end | |
# hard_clean_up(['hackership', 'market-place']) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment