Sha256: 55382e85073b862aad485233a1d508012a546cd9f91d76524d1ece76d54c25dc

Contents?: true

Size: 744 Bytes

Versions: 76

Compression:

Stored size: 744 Bytes

Contents

class MigrateOldPreferences < ActiveRecord::Migration[4.2]
  def up
    if Spree::Calculator.respond_to?(:with_deleted)
      migrate_preferences(Spree::Calculator.with_deleted)
    else
      migrate_preferences(Spree::Calculator)
    end
    migrate_preferences(Spree::PaymentMethod)
    migrate_preferences(Spree::PromotionRule)
  end

  def down
  end

  private
  def migrate_preferences klass
    klass.reset_column_information
    klass.find_each do |record|
      store = Spree::Preferences::ScopedStore.new(record.class.name.underscore, record.id)
      record.defined_preferences.each do |key|
        value = store.fetch(key){}
        record.preferences[key] = value unless value.nil?
      end
      record.save!
    end
  end
end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
spree_core-4.0.9 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.1.15 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.2.7 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.3.3 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.2.6 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.3.2 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.3.1 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.3.0 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.3.0.rc3 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.3.0.rc2 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.3.0.rc1 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.2.5 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.1.14 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.0.8 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.2.4 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-3.7.14.1 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.2.3.1 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.1.13.1 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.0.7.1 db/migrate/20140309023735_migrate_old_preferences.rb
spree_core-4.2.3 db/migrate/20140309023735_migrate_old_preferences.rb