2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-12 21:10:47 +08:00

BUGFIX: 500 error on some invalid uploads

This commit is contained in:
Sam 2014-05-14 10:51:09 +10:00
parent b329e23f85
commit ca4c72e648
2 changed files with 17 additions and 26 deletions

View file

@ -1,13 +1,19 @@
module RailsMultisite
class ConnectionManagement
CONFIG_FILE = 'config/multisite.yml'
DEFAULT = 'default'.freeze

def self.has_db?(db)
return true if db == DEFAULT
(defined? @@db_spec_cache) && @@db_spec_cache && @@db_spec_cache[db]
end

def self.rails4?
!!(Rails.version =~ /^4/)
end

def self.establish_connection(opts)
if opts[:db] == "default" && (!defined?(@@default_spec) || !@@default_spec)
if opts[:db] == DEFAULT && (!defined?(@@default_spec) || !@@default_spec)
# don't do anything .. handled implicitly
else
spec = connection_spec(opts) || @@default_spec
@ -119,33 +125,10 @@ module RailsMultisite

@@default_connection_handler = ActiveRecord::Base.connection_handler

# inject our connection_handler pool
# WARNING MONKEY PATCH
#
# see: https://github.com/rails/rails/issues/8344#issuecomment-10800848
if ActiveRecord::VERSION::MAJOR == 3
ActiveRecord::Base.send :include, NewConnectionHandler
ActiveRecord::Base.connection_handler = @@default_connection_handler
end

@@connection_handlers = {}
@@established_default = false
end

module NewConnectionHandler
def self.included(klass)
klass.class_eval do
define_singleton_method :connection_handler do
Thread.current[:connection_handler] || @connection_handler
end
define_singleton_method :connection_handler= do |handler|
@connection_handler ||= handler
Thread.current[:connection_handler] = handler
end
end
end
end


def initialize(app, config = nil)
@app = app