From 52718a41c09d16eddd161a77de5d5ee76f6e40c1 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 25 Sep 2015 17:15:41 +0200 Subject: [PATCH] Work for short time with :state_current and :state support. --- app/models/setting.rb | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/app/models/setting.rb b/app/models/setting.rb index c3483c4f2..ef8efb951 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -31,7 +31,11 @@ set config setting if !setting fail "Can't find config setting '#{name}'" end - setting.state_current = { value: value } + if setting.respond_to?(:state_current) + setting.state_current = { value: value } + else + setting.state = { value: value } + end setting.save logger.info "Setting.set(#{name}, #{value.inspect})" end @@ -66,9 +70,15 @@ reset config setting to default if !setting fail "Can't find config setting '#{name}'" end - setting.state_current = setting.state_initial - setting.save - logger.info "Setting.reset(#{name}, #{setting.state_current.inspect})" + 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 load @@current[:settings_config][name] end @@ -85,9 +95,16 @@ reset config setting to default # read all config settings config = {} - Setting.select('name, state_current').order(:id).each { |setting| - config[setting.name] = setting.state_current[:value] - } + 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 # config lookups config.each { |key, value| @@ -105,7 +122,11 @@ reset config setting to default # set initial value in state_initial def set_initial - self.state_initial = state_current + if self.respond_to?(:state_current) + self.state_initial = state_current + else + self.state_initial = state + end end # set new cache @@ -144,6 +165,10 @@ 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) - self.state_current = { value: state } + if self.respond_to?(:state_current) + self.state_current = { value: state } + else + self.state = { value: state } + end end end