mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Merge pull request #2949 from pfac/pfac-fix-new-preferences-migration
Fix new preferences migration
This commit is contained in:
@@ -1,4 +1,37 @@
|
||||
require 'spree/core/preference_rescue'
|
||||
# Spree 1.3.6.beta preference rescue implementation, required for the new
|
||||
# preferences migration, which is broken since commit ab707cf due to the
|
||||
# absence of this file.
|
||||
#
|
||||
# Migration: db/migrate/20120327000645_new_preferences.rb
|
||||
# Source: https://raw.githubusercontent.com/spree/spree/1-3-stable/core/lib/spree/core/preference_rescue.rb
|
||||
#
|
||||
# rubocop:disable all
|
||||
module Spree
|
||||
class OldPrefs < ActiveRecord::Base
|
||||
self.table_name = "spree_preferences"
|
||||
belongs_to :owner, :polymorphic => true
|
||||
attr_accessor :owner_klass
|
||||
end
|
||||
|
||||
class PreferenceRescue
|
||||
def self.try
|
||||
OldPrefs.where(:key => nil).each do |old_pref|
|
||||
next unless owner = (old_pref.owner rescue nil)
|
||||
unless old_pref.owner_type == "Spree::Activator" || old_pref.owner_type == "Spree::Configuration"
|
||||
begin
|
||||
old_pref.key = [owner.class.name, old_pref.name, owner.id].join('::').underscore
|
||||
old_pref.value_type = owner.preference_type(old_pref.name)
|
||||
puts "Migrating Preference: #{old_pref.key}"
|
||||
old_pref.save
|
||||
rescue NoMethodError => ex
|
||||
puts ex.message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# rubocop:enable all
|
||||
|
||||
class NewPreferences < ActiveRecord::Migration
|
||||
|
||||
@@ -45,4 +78,4 @@ class NewPreferences < ActiveRecord::Migration
|
||||
add_column :spree_preferences, :group_id, :integer
|
||||
add_column :spree_preferences, :group_type, :string
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user