diff --git a/app/models/pet_state.rb b/app/models/pet_state.rb index 0b3678b6..4af03079 100644 --- a/app/models/pet_state.rb +++ b/app/models/pet_state.rb @@ -135,6 +135,18 @@ class PetState < ActiveRecord::Base end end + def replace_with(other) + PetState.transaction do + count = outfits.count + outfits.find_each { |outfit| + outfit.pet_state = other + outfit.save! + } + destroy + end + count + end + def self.from_pet_type_and_biology_info(pet_type, info) swf_asset_ids = [] info.each do |zone_id, asset_info| diff --git a/lib/tasks/pet_states.rake b/lib/tasks/pet_states.rake new file mode 100644 index 00000000..95b90ec6 --- /dev/null +++ b/lib/tasks/pet_states.rake @@ -0,0 +1,13 @@ +namespace :pet_states do + desc "Sort pet state SWFs, then remove duplicates and reassign children" + task :repair => :environment do + PetState.repair_all! + end + + desc "Delete the bad pet state, replacing it in outfits with the good pet state" + task :replace, [:bad_id, :good_id] => :environment do |t, args| + bad, good = PetState.find(args[:bad_id], args[:good_id]) + outfit_count = bad.replace_with(good) + puts "Updated #{outfit_count} outfits" + end +end diff --git a/lib/tasks/repair_pet_states.rake b/lib/tasks/repair_pet_states.rake deleted file mode 100644 index f9d0d9bb..00000000 --- a/lib/tasks/repair_pet_states.rake +++ /dev/null @@ -1,6 +0,0 @@ -namespace :pet_states do - desc "Sort pet state SWFs, then remove duplicates and reassign children" - task :repair => :environment do - PetState.repair_all! - end -end