app/models/camaleon_cms/site.rb in camaleon_cms-2.3.6 vs app/models/camaleon_cms/site.rb in camaleon_cms-2.3.7
- old
+ new
@@ -1,7 +1,8 @@
class CamaleonCms::Site < CamaleonCms::TermTaxonomy
# attrs: [name, description, slug]
+ attr_accessor :site_domain
include CamaleonCms::SiteDefaultSettings
default_scope { where(taxonomy: :site).reorder(term_group: :desc) }
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, inverse_of: :site
@@ -111,11 +112,11 @@
get_option('need_validate_email', false) == true
end
# return main site
def self.main_site
- @main_site ||= CamaleonCms::Site.reorder(id: :ASC).first
+ @main_site ||= CamaleonCms::Site.reorder(id: :asc).first
end
# check if this site is the main site
# main site is a site that doesn't have slug
def main_site?
@@ -188,9 +189,16 @@
unless user.present?
pass = "anonymous#{rand(9999)}"
user = self.users.create({email: 'anonymous_user@local.com', username: 'anonymous', password: pass, password_confirmation: pass, first_name: 'Anonymous'})
end
user
+ end
+
+ # return the domain for current site
+ # sample: mysite.com | sample.mysite.com
+ # also, you can define custom domain for this site by: my_site.site_domain = 'my_site.com' # used for sites with different domains to call from console or task
+ def get_domain
+ @site_domain || (main_site? ? slug : (slug.include?(".") ? slug : "#{slug}.#{Cama::Site.main_site.slug}"))
end
private
# destroy all things before site destroy
def destroy_site