Commit 1d001e27117e1db616cd94013880848301cdf011
1 parent
824e34a2
Exists in
master
and in
22 other branches
Move multitenancy logic inside the multitenancy class
Showing
2 changed files
with
13 additions
and
6 deletions
Show diff stats
app/controllers/application_controller.rb
| 1 | class ApplicationController < ActionController::Base | 1 | class ApplicationController < ActionController::Base |
| 2 | 2 | ||
| 3 | - before_filter :change_pg_schema | 3 | + before_filter :setup_multitenancy |
| 4 | 4 | ||
| 5 | include ApplicationHelper | 5 | include ApplicationHelper |
| 6 | layout :get_layout | 6 | layout :get_layout |
| @@ -67,10 +67,8 @@ class ApplicationController < ActionController::Base | @@ -67,10 +67,8 @@ class ApplicationController < ActionController::Base | ||
| 67 | 67 | ||
| 68 | protected | 68 | protected |
| 69 | 69 | ||
| 70 | - def change_pg_schema | ||
| 71 | - if Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql? | ||
| 72 | - Noosfero::MultiTenancy.db_by_host = request.host | ||
| 73 | - end | 70 | + def setup_multitenancy |
| 71 | + Noosfero::MultiTenancy.setup!(request.host) | ||
| 74 | end | 72 | end |
| 75 | 73 | ||
| 76 | def boxes_editor? | 74 | def boxes_editor? |
lib/noosfero/multi_tenancy.rb
| @@ -10,7 +10,16 @@ module Noosfero | @@ -10,7 +10,16 @@ module Noosfero | ||
| 10 | end | 10 | end |
| 11 | 11 | ||
| 12 | def self.db_by_host=(host) | 12 | def self.db_by_host=(host) |
| 13 | - ActiveRecord::Base.connection.schema_search_path = self.mapping[host] | 13 | + if host != @db_by_host |
| 14 | + @db_by_host = host | ||
| 15 | + ActiveRecord::Base.connection.schema_search_path = self.mapping[host] | ||
| 16 | + end | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | + def self.setup!(host) | ||
| 20 | + if Noosfero::MultiTenancy.on? and ActiveRecord::Base.postgresql? | ||
| 21 | + Noosfero::MultiTenancy.db_by_host = host | ||
| 22 | + end | ||
| 14 | end | 23 | end |
| 15 | 24 | ||
| 16 | private | 25 | private |