do not register plugin settings at load time. this commit registers plugin settings, when they are registered.

pull/1186/head
Martin Linkhorst 12 years ago
parent 5e4a766758
commit b445387e7a
  1. 54
      app/models/setting.rb
  2. 5
      lib/redmine/plugin.rb

@ -72,10 +72,38 @@ class Setting < ActiveRecord::Base
TIS-620)
cattr_accessor :available_settings
def self.create_setting(name, value = nil)
@@available_settings[name] = value
end
def self.create_setting_accessors(name)
# Defines getter and setter for each setting
# Then setting values can be read using: Setting.some_setting_name
# or set using Setting.some_setting_name = "some value"
src = <<-END_SRC
def self.#{name}
self[:#{name}]
end
def self.#{name}?
self[:#{name}].to_i > 0
end
def self.#{name}=(value)
self[:#{name}] = value
end
END_SRC
class_eval src, __FILE__, __LINE__
end
@@available_settings = YAML::load(File.open(Rails.root.join('config/settings.yml')))
Redmine::Plugin.all.each do |plugin|
next unless plugin.settings
@@available_settings["plugin_#{plugin.id}"] = {'default' => plugin.settings[:default], 'serialized' => true}
# Defines getter and setter for each setting
# Then setting values can be read using: Setting.some_setting_name
# or set using Setting.some_setting_name = "some value"
@@available_settings.each do |name, params|
self.create_setting_accessors(name)
end
validates_uniqueness_of :name
@ -108,26 +136,6 @@ class Setting < ActiveRecord::Base
setting.value
end
# Defines getter and setter for each setting
# Then setting values can be read using: Setting.some_setting_name
# or set using Setting.some_setting_name = "some value"
@@available_settings.each do |name, params|
src = <<-END_SRC
def self.#{name}
self[:#{name}]
end
def self.#{name}?
self[:#{name}].to_i > 0
end
def self.#{name}=(value)
self[:#{name}] = value
end
END_SRC
class_eval src, __FILE__, __LINE__
end
# this should be fixed with globalize plugin
[:emails_header, :emails_footer].each do |mail|
src = <<-END_SRC

@ -91,6 +91,11 @@ module Redmine #:nodoc:
::I18n.load_path += Dir.glob(Rails.root.join('vendor/plugins', id.to_s, 'config/locales/*.yml'))
registered_plugins[id] = p
if p.settings
Setting.create_setting("plugin_#{id}", {'default' => p.settings[:default], 'serialized' => true})
Setting.create_setting_accessors("plugin_#{id}")
end
# If there are plugins waiting for us to be loaded, we try loading those, again
if deferred_plugins[id]
deferred_plugins[id].each do |ary|

Loading…
Cancel
Save