Sha256: 304b3bd9214f780bbbf06cc8789f7bdf1ea4f1a0c645b4669e2a7d62a0b8534c

Contents?: true

Size: 1.32 KB

Versions: 35

Compression:

Stored size: 1.32 KB

Contents

class MigrateDonationTypes < ActiveRecord::Migration
  def update_action_and_order(action, new_subtype, payment_method=nil)
    puts "Fixing Action #{action.id} -----------------------------------------"
    puts "Old subtype #{action.subtype}"
    puts "New subtype #{new_subtype}"
    action.subtype = new_subtype
    saved = action.save
    puts "Saved #{saved}"
    
    if action.subject.nil?
      puts "No order found"
    elsif payment_method.nil?
      puts "No change to payment method"
    else
      puts "Fixing Order #{action.subject.id}"
      puts "Old payment method #{action.subject.payment_method}"
      puts "New payment method #{payment_method}"
      action.subject.payment_method = payment_method
      saved = action.subject.save
      puts "Saved #{saved}"
    end
  end
  
  def change
    Action.where(:subtype => 'Donation').each do |action|
      update_action_and_order(action, "Monetary")
    end
    
    Action.where(:subtype => 'Donation (Cash)').each do |action|
      update_action_and_order(action, "Monetary", "Cash")
    end
    
    Action.where(:subtype => 'Donation (Check)').each do |action|
      update_action_and_order(action, "Monetary", "Check")
    end
    
    Action.where(:subtype => 'Donation (In-Kind)').each do |action|
      update_action_and_order(action, "In-Kind", "Other")
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.11 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.10 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.9 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.8 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.7 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.6 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.5 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.4 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.3 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.2 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.1 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.1.0 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.1.0.rc2 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.1.0.rc1 db/migrate/20121113144826_migrate_donation_types.rb