0
@@ -26,7 +26,7 @@ class Site < ActiveRecord::Base
0
@@template_handlers.keys
0
- has_many :sections, :order => "position"
do
0
+ has_many :sections, :order => "position"
, :dependent => :destroy do
0
@@ -41,7 +41,7 @@ class Site < ActiveRecord::Base
0
+ has_many :articles
, :dependent => :destroy do
0
def find_by_permalink(options)
0
returning ["(contents.published_at IS NOT NULL AND contents.published_at <= ?)", Time.now.utc] do |cond|
0
@@ -63,13 +63,13 @@ class Site < ActiveRecord::Base
0
- has_many :comments, :order => 'comments.created_at desc'
0
+ has_many :comments, :order => 'comments.created_at desc'
, :dependent => :delete_all0
+ has_many :events
, :dependent => :destroy0
- has_many :cached_pages
0
+ has_many :cached_pages
, :dependent => :destroy0
- has_many :assets, :order => 'created_at desc', :conditions => 'parent_id is null'
0
+ has_many :assets, :order => 'created_at desc', :conditions => 'parent_id is null'
, :dependent => :destroy0
has_many :memberships, :dependent => :destroy
0
has_many :members, :through => :memberships, :source => :user
0
@@ -82,13 +82,23 @@ class Site < ActiveRecord::Base
0
validates_format_of :host, :with => Format::DOMAIN
0
validates_uniqueness_of :host
0
validate :check_permalink_style
0
- after_create { |s| s.sections.create(:name => 'Home') }
0
+ before_create :setup_site_theme_directories
0
+ after_create { |site| site.sections.create(:name => 'Home') }
0
+ before_destroy :flush_cache_and_remove_site_directories
0
with_options :order => 'contents.created_at DESC', :class_name => 'Comment' do |comment|
0
comment.has_many :comments, :conditions => ['contents.approved = ?', true]
0
comment.has_many :unapproved_comments, :conditions => ['contents.approved = ? or contents.approved is null', false]
0
comment.has_many :all_comments
0
+ def self.search_by_host_or_title(search_string)
0
+ conditions = search_string.blank? ? nil : ["host LIKE ? OR title LIKE ?"] + ["%#{search_string}%"] * 2
0
+ with_scope( :find => { :conditions => conditions } ) do
0
def users(options = {})
0
User.find_all_by_site self, options
0
@@ -297,4 +307,32 @@ class Site < ActiveRecord::Base
0
find_preferred_template(:layout, layout_template)
0
+ def setup_site_theme_directories
0
+ theme_path = "#{RAILS_ROOT}/themes/site-#{self.id}/simpla"
0
+ FileUtils.mkdir_p("#{RAILS_ROOT}/themes/site-#{self.id}")
0
+ FileUtils.cp_r("#{RAILS_ROOT}/themes/default", theme_path)
0
+ Dir[File.join(theme_path, '**/.svn')].each do |dir|
0
+ logger.error "ERROR: removing directories for site #{self.host}, check file permissions."
0
+ errors.add_to_base "Unable to create theme directories."
0
+ def flush_cache_and_remove_site_directories
0
+ CachedPage.expire_pages self, self.cached_pages
0
+ FileUtils.rm_rf("#{RAILS_ROOT}/themes/site-#{self.id}")
0
+ FileUtils.rm_rf("#{RAILS_ROOT}/public/cache/#{self.host}")
0
+ logger.error "ERROR: removing directories for site #{self.host}, check file permissions."
Comments
No one has commented yet.