diff --git a/Gemfile b/Gemfile index babdca6f..4a71e04b 100644 --- a/Gemfile +++ b/Gemfile @@ -70,8 +70,4 @@ group :development do #gem 'common_deploy', require: false, path: '../../common_deploy' # pending foodcoops/foodsoft#34, git: 'git://github.com/fsmanuel/common_deploy.git' # Avoid having content-length warnings gem 'thin' -end - -# Gems left for backwards compatibility -gem 'acts_as_configurable', git: 'git://github.com/bwalding/acts_as_configurable.git' # user settings migration needs it - +end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index a425f25f..52b3bd39 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,13 +4,6 @@ GIT specs: localize_input (0.1.0) -GIT - remote: git://github.com/bwalding/acts_as_configurable.git - revision: cdf6f6f979019275b523d10684b748f08e2dd8e8 - specs: - acts_as_configurable (0.0.1) - rake - GIT remote: git://github.com/technoweenie/acts_as_versioned.git revision: 63b1fc8529d028fae632fe80ec0cb25df56cd76b @@ -263,7 +256,6 @@ PLATFORMS ruby DEPENDENCIES - acts_as_configurable! acts_as_tree acts_as_versioned! better_errors diff --git a/db/migrate/20130718183101_migrate_user_settings.rb b/db/migrate/20130718183101_migrate_user_settings.rb index a9722f1b..428608d0 100644 --- a/db/migrate/20130718183101_migrate_user_settings.rb +++ b/db/migrate/20130718183101_migrate_user_settings.rb @@ -1,34 +1,46 @@ class MigrateUserSettings < ActiveRecord::Migration def up - old_settings = ConfigurableSetting.all - - old_settings.each do |old_setting| - # get target (user) - type = old_setting.configurable_type - id = old_setting.configurable_id - user = type.constantize.find(id) - - # get the data (settings) - name = old_setting.name - namespace = name.split('.')[0] - key = name.split('.')[1].underscore # Camelcase to underscore - - # prepare value - value = YAML.load(old_setting.value) - value = value.nil? ? false : value - - # set the settings_attributes (thanks to settings.merge! we can set them one by one) - user.settings_attributes = { - "#{namespace}" => { - "#{key}" => value + say_with_time 'Save old user settings in new RailsSettings module' do + old_settings = ConfigurableSetting.all + + old_settings.each do |old_setting| + # get target (user) + type = old_setting.configurable_type + id = old_setting.configurable_id + begin + user = type.constantize.find(id) + rescue ActiveRecord::RecordNotFound + Rails.logger.debug "Can't find configurable object with type: #{type.inspect}, id: #{id.inspect}" + next + end + + # get the data (settings) + name = old_setting.name + namespace = name.split('.')[0] + key = name.split('.')[1].underscore # Camelcase to underscore + + # prepare value + value = YAML.load(old_setting.value) + value = value.nil? ? false : value + + # set the settings_attributes (thanks to settings.merge! we can set them one by one) + user.settings_attributes = { + "#{namespace}" => { + "#{key}" => value + } } - } - - # save the user to apply after_save callback - user.save + + # save the user to apply after_save callback + user.save + end end + + drop_table :configurable_settings end def down end end + +# this is the base class of all configurable settings +class ConfigurableSetting < ActiveRecord::Base; end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 03d86aba..0d5b1326 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -66,18 +66,6 @@ ActiveRecord::Schema.define(:version => 20130718183101) do add_index "assignments", ["user_id", "task_id"], :name => "index_assignments_on_user_id_and_task_id", :unique => true - create_table "configurable_settings", :force => true do |t| - t.integer "configurable_id" - t.string "configurable_type" - t.integer "targetable_id" - t.string "targetable_type" - t.string "name", :default => "", :null => false - t.string "value_type" - t.text "value" - end - - add_index "configurable_settings", ["name"], :name => "index_configurable_settings_on_name" - create_table "deliveries", :force => true do |t| t.integer "supplier_id" t.date "delivered_on"