From 4946c406790f55c0eb66f25d575e6e173c9f354f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 25 Sep 2015 20:35:36 +0200 Subject: [PATCH] Fixed change of value / value_current. --- app/models/setting.rb | 43 ++++--------------- config/initializers/logo.rb | 4 +- db/migrate/20120101000001_create_base.rb | 4 +- db/migrate/20150978000001_update_settings6.rb | 7 +++ 4 files changed, 21 insertions(+), 37 deletions(-) create mode 100644 db/migrate/20150978000001_update_settings6.rb diff --git a/app/models/setting.rb b/app/models/setting.rb index ef8efb951..c3483c4f2 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -31,11 +31,7 @@ set config setting if !setting fail "Can't find config setting '#{name}'" end - if setting.respond_to?(:state_current) - setting.state_current = { value: value } - else - setting.state = { value: value } - end + setting.state_current = { value: value } setting.save logger.info "Setting.set(#{name}, #{value.inspect})" end @@ -70,15 +66,9 @@ reset config setting to default if !setting fail "Can't find config setting '#{name}'" end - if setting.respond_to?(:state_current) - setting.state_current = setting.state_initial - setting.save - logger.info "Setting.reset(#{name}, #{setting.state_current.inspect})" - else - setting.state = setting.state_initial - setting.save - logger.info "Setting.reset(#{name}, #{setting.state_current.inspect})" - end + setting.state_current = setting.state_initial + setting.save + logger.info "Setting.reset(#{name}, #{setting.state_current.inspect})" load @@current[:settings_config][name] end @@ -95,16 +85,9 @@ reset config setting to default # read all config settings config = {} - s = Setting.new - if s.respond_to?(:state_current) - Setting.select('name, state_current').order(:id).each { |setting| - config[setting.name] = setting.state_current[:value] - } - else - Setting.select('name, state').order(:id).each { |setting| - config[setting.name] = setting.state[:value] - } - end + Setting.select('name, state_current').order(:id).each { |setting| + config[setting.name] = setting.state_current[:value] + } # config lookups config.each { |key, value| @@ -122,11 +105,7 @@ reset config setting to default # set initial value in state_initial def set_initial - if self.respond_to?(:state_current) - self.state_initial = state_current - else - self.state_initial = state - end + self.state_initial = state_current end # set new cache @@ -165,10 +144,6 @@ reset config setting to default # convert state ot hash to be able to store it as store def state_check return if state && state.respond_to?('has_key?') && state.key?(:value) - if self.respond_to?(:state_current) - self.state_current = { value: state } - else - self.state = { value: state } - end + self.state_current = { value: state } end end diff --git a/config/initializers/logo.rb b/config/initializers/logo.rb index 00e77ca23..4980b69d5 100644 --- a/config/initializers/logo.rb +++ b/config/initializers/logo.rb @@ -1,4 +1,6 @@ # sync logo to fs / only if settings already exists if ActiveRecord::Base.connection.tables.include?('settings') - StaticAssets.sync + if Setting.column_names.include?('state_current') + StaticAssets.sync + end end diff --git a/db/migrate/20120101000001_create_base.rb b/db/migrate/20120101000001_create_base.rb index d5cdcfedd..677fc1e66 100644 --- a/db/migrate/20120101000001_create_base.rb +++ b/db/migrate/20120101000001_create_base.rb @@ -210,7 +210,7 @@ class CreateBase < ActiveRecord::Migration t.string :client_id, null: false t.string :key, limit: 100, null: false t.string :callback, limit: 100, null: false - t.string :state, limit: 8000, null: true + t.column :state, :text, limit: 2.megabytes + 1, null: true t.string :params, limit: 2000, null: true t.integer :prio, null: false t.boolean :notify, null: false, default: false @@ -320,7 +320,7 @@ class CreateBase < ActiveRecord::Migration t.string :area, limit: 100, null: false t.string :description, limit: 2000, null: false t.string :options, limit: 2000, null: true - t.string :state, limit: 2000, null: true + t.string :state_current, limit: 2000, null: true t.string :state_initial, limit: 2000, null: true t.boolean :frontend, null: false t.timestamps diff --git a/db/migrate/20150978000001_update_settings6.rb b/db/migrate/20150978000001_update_settings6.rb new file mode 100644 index 000000000..73f85ecc7 --- /dev/null +++ b/db/migrate/20150978000001_update_settings6.rb @@ -0,0 +1,7 @@ +class UpdateSettings6 < ActiveRecord::Migration + def up + if Setting.column_names.include?('state') + rename_column :settings, :state, :state_current + end + end +end