app/models/camaleon_cms/site.rb in camaleon_cms-2.1.1.4 vs app/models/camaleon_cms/site.rb in camaleon_cms-2.1.2.0
- old
+ new
@@ -7,11 +7,11 @@
See the GNU Affero General Public License (GPLv3) for more details.
=end
class CamaleonCms::Site < CamaleonCms::TermTaxonomy
# attrs: [name, description, slug]
default_scope { where(taxonomy: :site).reorder(term_group: :desc) }
- has_many :metas, -> { where(object_class: 'Site') }, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
+ has_many :metas, -> { where(object_class: 'Site') }, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :delete_all
has_many :post_types, :class_name => "CamaleonCms::PostType", foreign_key: :parent_id, dependent: :destroy
has_many :nav_menus, :class_name => "CamaleonCms::NavMenu", foreign_key: :parent_id, dependent: :destroy
has_many :nav_menu_items, :class_name => "CamaleonCms::NavMenuItem", foreign_key: :term_group
has_many :widgets, :class_name => "CamaleonCms::Widget::Main", foreign_key: :parent_id, dependent: :destroy
has_many :sidebars, :class_name => "CamaleonCms::Widget::Sidebar", foreign_key: :parent_id, dependent: :destroy
@@ -26,10 +26,11 @@
after_create :default_settings
after_create :set_all_users
after_create :set_default_user_roles
after_save :update_routes
before_destroy :destroy_site
+ after_destroy :reload_routes
validates_uniqueness_of :slug, scope: :taxonomy
# all user roles for this site
def user_roles
if PluginRoutes.system_info["users_share_sites"]
@@ -234,10 +235,25 @@
end
res
end
end
+ # check if current site is active or not
+ def is_active?
+ !self.status.present? || self.status == 'active'
+ end
+
+ # check if current site is active or not
+ def is_inactive?
+ self.status == 'inactive'
+ end
+
+ # check if current site is in maintenance or not
+ def is_maintenance?
+ self.status == 'maintenance'
+ end
+
private
# destroy all things before site destroy
def destroy_site
unless PluginRoutes.system_info["users_share_sites"]
CamaleonCms::User.where(site_id: self.id).destroy_all
@@ -248,11 +264,11 @@
# default structure for each new site
def default_settings
default_post_type = [
{name: 'Post', description: 'Posts', options: {has_category: true, has_tags: true, not_deleted: true, has_summary: true, has_content: true, has_comments: true, has_picture: true, has_template: true, }},
- {name: 'Page', description: 'Pages', options: {has_category: false, has_tags: false, not_deleted: true, has_summary: false, has_content: true, has_comments: false, has_picture: true, has_template: true, }}
+ {name: 'Page', description: 'Pages', options: {has_category: false, has_tags: false, not_deleted: true, has_summary: false, has_content: true, has_comments: false, has_picture: true, has_template: true, has_layout: true}}
]
default_post_type.each do |pt|
model_pt = self.post_types.create({name: pt[:name], slug: pt[:name].to_s.parameterize, description: pt[:description], data_options: pt[:options]})
end
@@ -286,9 +302,13 @@
# update all routes of the system
# reload system routes for this site
def update_routes
PluginRoutes.reload if self.slug_changed?
+ end
+
+ def reload_routes
+ PluginRoutes.reload
end
def before_validating
slug = self.slug
slug = self.name if slug.blank?
\ No newline at end of file