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.3.0.pre4 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.3.0.pre3 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.3.0.pre2 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.3.0.pre1 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.beta.1 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.alpha.2 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.alpha.1 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.27 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.26 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.24 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.23 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.21 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.20 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.19 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.18 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.17 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.16 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.15 db/migrate/20121113144826_migrate_donation_types.rb
artfully_ose-1.2.0.pre.12 db/migrate/20121113144826_migrate_donation_types.rb