annotate lib/redmine/configuration.rb @ 1600:ed9c467ef922 dockerise

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