annotate .svn/pristine/b7/b79791de4d5f7b498396b0a1261c36b1da41245f.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 module Redmine
Chris@909 19 module Configuration
Chris@909 20
Chris@909 21 # Configuration default values
Chris@909 22 @defaults = {
Chris@909 23 'email_delivery' => nil
Chris@909 24 }
Chris@909 25
Chris@909 26 @config = nil
Chris@909 27
Chris@909 28 class << self
Chris@909 29 # Loads the Redmine configuration file
Chris@909 30 # Valid options:
Chris@909 31 # * <tt>:file</tt>: the configuration file to load (default: config/configuration.yml)
Chris@909 32 # * <tt>:env</tt>: the environment to load the configuration for (default: Rails.env)
Chris@909 33 def load(options={})
Chris@909 34 filename = options[:file] || File.join(Rails.root, 'config', 'configuration.yml')
Chris@909 35 env = options[:env] || Rails.env
Chris@909 36
Chris@909 37 @config = @defaults.dup
Chris@909 38
Chris@909 39 load_deprecated_email_configuration(env)
Chris@909 40 if File.file?(filename)
Chris@909 41 @config.merge!(load_from_yaml(filename, env))
Chris@909 42 end
Chris@909 43
Chris@909 44 # Compatibility mode for those who copy email.yml over configuration.yml
Chris@909 45 %w(delivery_method smtp_settings sendmail_settings).each do |key|
Chris@909 46 if value = @config.delete(key)
Chris@909 47 @config['email_delivery'] ||= {}
Chris@909 48 @config['email_delivery'][key] = value
Chris@909 49 end
Chris@909 50 end
Chris@909 51
Chris@909 52 if @config['email_delivery']
Chris@909 53 ActionMailer::Base.perform_deliveries = true
Chris@909 54 @config['email_delivery'].each do |k, v|
Chris@909 55 v.symbolize_keys! if v.respond_to?(:symbolize_keys!)
Chris@909 56 ActionMailer::Base.send("#{k}=", v)
Chris@909 57 end
Chris@909 58 end
Chris@909 59
Chris@909 60 @config
Chris@909 61 end
Chris@909 62
Chris@909 63 # Returns a configuration setting
Chris@909 64 def [](name)
Chris@909 65 load unless @config
Chris@909 66 @config[name]
Chris@909 67 end
Chris@909 68
Chris@909 69 # Yields a block with the specified hash configuration settings
Chris@909 70 def with(settings)
Chris@909 71 settings.stringify_keys!
Chris@909 72 load unless @config
Chris@909 73 was = settings.keys.inject({}) {|h,v| h[v] = @config[v]; h}
Chris@909 74 @config.merge! settings
Chris@909 75 yield if block_given?
Chris@909 76 @config.merge! was
Chris@909 77 end
Chris@909 78
Chris@909 79 private
Chris@909 80
Chris@909 81 def load_from_yaml(filename, env)
Chris@909 82 yaml = nil
Chris@909 83 begin
Chris@909 84 yaml = YAML::load_file(filename)
Chris@909 85 rescue ArgumentError
Chris@909 86 $stderr.puts "Your Redmine configuration file located at #{filename} is not a valid YAML file and could not be loaded."
Chris@909 87 exit 1
Chris@909 88 end
Chris@909 89 conf = {}
Chris@909 90 if yaml.is_a?(Hash)
Chris@909 91 if yaml['default']
Chris@909 92 conf.merge!(yaml['default'])
Chris@909 93 end
Chris@909 94 if yaml[env]
Chris@909 95 conf.merge!(yaml[env])
Chris@909 96 end
Chris@909 97 else
Chris@909 98 $stderr.puts "Your Redmine configuration file located at #{filename} is not a valid Redmine configuration file."
Chris@909 99 exit 1
Chris@909 100 end
Chris@909 101 conf
Chris@909 102 end
Chris@909 103
Chris@909 104 def load_deprecated_email_configuration(env)
Chris@909 105 deprecated_email_conf = File.join(Rails.root, 'config', 'email.yml')
Chris@909 106 if File.file?(deprecated_email_conf)
Chris@909 107 warn "Storing outgoing emails configuration in config/email.yml is deprecated. You should now store it in config/configuration.yml using the email_delivery setting."
Chris@909 108 @config.merge!({'email_delivery' => load_from_yaml(deprecated_email_conf, env)})
Chris@909 109 end
Chris@909 110 end
Chris@909 111 end
Chris@909 112 end
Chris@909 113 end