more robust settings in pre-merge phase

when we haven't migrated yet, there is no settings table.
this doesn't hinder plugins to read/write settings (when
initializing the app).

solution: ignore setting-writes (but give a warning) and
answer an empty hash on setting-read when there is no
setting-table.

fixes #1830
pull/386/head
Philipp Tessenow 11 years ago
parent 2d130b03c0
commit 220bc5eb38
  1. 13
      app/models/setting.rb

@ -81,15 +81,28 @@ class Setting < ActiveRecord::Base
# or set using Setting.some_setting_name = "some value"
src = <<-END_SRC
def self.#{name}
if connection.table_exists?(table_name)
self[:#{name}]
else
{} # when runnung too early, there is no settings table. do nothing
end
end
def self.#{name}?
if connection.table_exists?(table_name)
self[:#{name}].to_i > 0
else
{} # when runnung too early, there is no settings table. do nothing
end
end
def self.#{name}=(value)
if connection.table_exists?(table_name)
self[:#{name}] = value
else
logger.warn "Trying to save a setting named '#{name}' while there is no 'setting' table yet. This setting will not be saved!"
{} # when runnung too early, there is no settings table. do nothing
end
end
END_SRC
class_eval src, __FILE__, __LINE__

Loading…
Cancel
Save