camaleon_cms 2.4.3.10 → 2.4.3.11

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of camaleon_cms might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e2c1cbc2531d17c63a5317bb57e961408dab39b
4
- data.tar.gz: cff019aa57448db963680967ddb1a209b56b2143
3
+ metadata.gz: 9dc8afe6e7c379d3328182cf9beb596c2dfa9d48
4
+ data.tar.gz: 079a90ef92547c8f8dbc3b3a9a65b9a6530ed151
5
5
  SHA512:
6
- metadata.gz: 7400272b9477b97f50385392d92a769cb57e289c8103315c80932e9a3f4e8429012404ba06c50f9be3e618abb3ded4663ed6c755a8c22f64f4cd95ceabcadecb
7
- data.tar.gz: ef4f45ba429bcb5af986510176ede320a24e06bfbdbc4dc3eb00cef544ee79d7cc920307a8cbc1c99ebdb500eaadf7c4e0f149a91a0baa9b1601d3fcb48cb4e7
6
+ metadata.gz: 802f6d4b4211b05561bd69bc4122ff489509ce7b66c652acf9f75c8a699d2d3e1376380c78a550a83c7b38b26e2327a28b4c037875adc3659b727d76b6d9391d
7
+ data.tar.gz: 15ae7e350976a0138e0dcddb1ff5afdc5797570b32a728d368780b43e252f4975f52ceffc5bb4af2b4b3c8084640e5f70cd9eba268d34fac19948398e4a4fbae
data/README.md CHANGED
@@ -39,7 +39,7 @@
39
39
  * Add the gem in your Gemfile
40
40
 
41
41
  ```
42
- gem "camaleon_cms", '>= 2.4.3.6' # Stable versions 2.4.3.5, 2.4.3.2, 2.3.6, 2.2.1, 2.1.1, 2.1.0
42
+ gem "camaleon_cms", '>= 2.4.3.10' # Stable versions 2.4.3.6, 2.4.3.5, 2.4.3.2, 2.3.6, 2.2.1, 2.1.1, 2.1.0
43
43
  # gem "camaleon_cms", github: 'owen2345/camaleon-cms' # current development version
44
44
  ```
45
45
  * Only Rails 5 support
@@ -12,7 +12,9 @@ class Plugins::FrontCache::AdminController < CamaleonCms::Apps::PluginsAdminCont
12
12
  skip_posts: (params[:cache][:skip_posts]||[]),
13
13
  cache_login: params[:cache][:cache_login],
14
14
  home: params[:cache][:home],
15
- preserve_cache_on_restart: params[:cache][:preserve_cache_on_restart]
15
+ preserve_cache_on_restart: params[:cache][:preserve_cache_on_restart],
16
+ invalidate_only: params[:cache][:invalidate_only],
17
+ cache_counter: current_site.get_meta("front_cache_elements")[:cache_counter] || 0
16
18
  })
17
19
  flash[:notice] = "#{t('plugin.front_cache.message.settings_saved')}"
18
20
  redirect_to action: :settings
@@ -12,6 +12,8 @@ en:
12
12
  pages: 'Pages'
13
13
  pages_of: 'Pages of'
14
14
  skip_cache_pages: 'Skip Cache Pages'
15
+ preserve_cache_on_restart: 'Preserve cache on restart'
16
+ invalidate_only: 'Invalidate the cache instead of deleting it. (Recommended only if you use custom caching in your views. Not recommended when using FileStore, which is the Rails default cache)'
15
17
  message:
16
18
  please_checkpost_need_cache: 'Please check all posts or post types you need to cache.'
17
19
  enabled_cache_inner_content_logged_users: 'Enable cache for inner content for logged users'
@@ -31,6 +33,8 @@ es:
31
33
  pages: 'Página'
32
34
  pages_of: 'Página de'
33
35
  skip_cache_pages: 'Saltar página del Caché'
36
+ preserve_cache_on_restart: 'Preservar caché al reiniciar'
37
+ invalidate_only: 'Invalide el caché en lugar de eliminarlo. (Recomendado sólo si utiliza el almacenamiento en caché personalizado en sus vistas No se recomienda cuando se utiliza FileStore, que es la caché predeterminada de Rails)'
34
38
  message:
35
39
  please_checkpost_need_cache: 'Por favor, compruebe todos los mensajes o los tipos de correos que necesita para almacenar en caché.'
36
40
  enabled_cache_inner_content_logged_users: 'Habilitar caché de contenido interno para usuarios registrados'
@@ -51,6 +55,8 @@ nl:
51
55
  pages: "Pagina's"
52
56
  pages_of: "Inhoud van"
53
57
  skip_cache_pages: 'Cache overslaan'
58
+ preserve_cache_on_restart: 'Bewaar cache bij herstarten'
59
+ invalidate_only: 'De cache ongeldig maken, in plaats van het te verwijderen. (Alleen aanbevolen als u aangepaste caching gebruikt in uw weergaven. Niet aanbevolen bij het gebruik van FileStore, wat is de standaard cache van de Rails)'
54
60
  message:
55
61
  please_checkpost_need_cache: "Kijk alle berichten of inhoud type's na die je wil cachen."
56
62
  enabled_cache_inner_content_logged_users: 'Activeer cache voor gelogde gebruikers'
@@ -70,6 +76,8 @@ pt-BR:
70
76
  pages: 'Páginas'
71
77
  pages_of: 'Páginas de'
72
78
  skip_cache_pages: 'Saltar Cache de Páginas'
79
+ preserve_cache_on_restart: 'Preserve o cache no reinício'
80
+ invalidate_only: 'Invalide o cache em vez de excluí-lo. (Recomendado apenas se você usar cache personalizado em suas visualizações. Não recomendado quando usar FileStore, que é o cache padrão do Rails)'
73
81
  message:
74
82
  please_checkpost_need_cache: 'Por favor verifique todas as publicações ou o tipo do publicação que precisa colocar em cache.'
75
83
  enabled_cache_inner_content_logged_users: 'Permitir cache para conteúdo interno de utilizadores ligados'
@@ -89,6 +97,8 @@ pt-BR:
89
97
  pages: 'Páginas'
90
98
  pages_of: 'Páginas de'
91
99
  skip_cache_pages: 'Pular Cache de Páginas'
100
+ preserve_cache_on_restart: 'Preserve o cache no reinício'
101
+ invalidate_only: 'Invalide o cache em vez de excluí-lo. (Recomendado apenas se você usar cache personalizado em suas visualizações. Não recomendado quando usar FileStore, que é o cache padrão do Rails)'
92
102
  message:
93
103
  please_checkpost_need_cache: 'Por favor cheque todos os posts ou o tipo do post que você precisa cachear.'
94
104
  enabled_cache_inner_content_logged_users: 'Permitir cache para conteúdo interno de usuários logados'
@@ -108,6 +118,8 @@ it:
108
118
  pages: 'Pagine'
109
119
  pages_of: 'Pagine di'
110
120
  skip_cache_pages: 'Pagine da non cachare'
121
+ preserve_cache_on_restart: 'Conserva la cache al riavvio'
122
+ invalidate_only: 'Invalidate la cache invece di cancellarla. (Consigliato solo se si utilizza la cache personalizzata nelle tue viste. Non è consigliata quando si utilizza FileStore, che è la cache predefinita Rails)'
111
123
  message:
112
124
  please_checkpost_need_cache: 'Per favore, verifica tutti i tipi di messaggi o e-mail che è necessario memorizzare nella cache.'
113
125
  enabled_cache_inner_content_logged_users: 'Attiva il contenuto della cache interna per gli utenti registrati'
@@ -127,10 +139,11 @@ zh-CN:
127
139
  pages: '页面'
128
140
  pages_of: '页'
129
141
  skip_cache_pages: '跳过缓存页面'
142
+ preserve_cache_on_restart: '重新启动时保存缓存'
143
+ invalidate_only: '使缓存无效,而不是删除它。 (仅当您在视图中使用自定义缓存时才推荐使用FileStore时,建议不要使用Rails默认缓存)'
130
144
  message:
131
145
  please_checkpost_need_cache: '请检查您需要缓存位内容.'
132
146
  enabled_cache_inner_content_logged_users: '为已登录的用户启用内部内容的缓存'
133
147
  settings_saved: '设置已保存!'
134
148
  cache_destroyed: '缓存已清楚!'
135
149
  settings: '设置'
136
-
@@ -10,6 +10,7 @@ module Plugins::FrontCache::FrontCacheHelper
10
10
  return if signin? || Rails.env == "development" || Rails.env == "test" || !request.get? # avoid cache if current visitor is logged in or development environment
11
11
 
12
12
  cache_key = request.fullpath.parameterize
13
+ @caches = current_site.get_meta("front_cache_elements")
13
14
  if !flash.keys.present? && front_cache_exist?(cache_key) # recover cache item
14
15
  Rails.logger.info "Camaleon CMS - readed cache: #{front_cache_plugin_get_path(cache_key)}"
15
16
  response.headers['PLUGIN_FRONT_CACHE'] = 'TRUE'
@@ -18,7 +19,6 @@ module Plugins::FrontCache::FrontCacheHelper
18
19
  return
19
20
  end
20
21
 
21
- @caches = current_site.get_meta("front_cache_elements")
22
22
  @_plugin_do_cache = false
23
23
  if @caches[:paths].include?(request.original_url) || @caches[:paths].include?(request.path_info) || front_cache_plugin_match_path_patterns?(request.original_url, request.path_info) || (params[:action] == 'index' && params[:controller] == 'camaleon_cms/frontend' && @caches[:home].present?) # cache paths and home page
24
24
  @_plugin_do_cache = true
@@ -59,7 +59,8 @@ module Plugins::FrontCache::FrontCacheHelper
59
59
  post_types: [current_site.post_types.where(slug: "page").first.id],
60
60
  skip_posts: [],
61
61
  home: true,
62
- cache_login: true}) unless current_site.get_meta("front_cache_elements", nil).present?
62
+ cache_login: true,
63
+ cache_counter: 0}) unless current_site.get_meta("front_cache_elements", nil).present?
63
64
  end
64
65
 
65
66
  # on uninstall plugin
@@ -89,17 +90,25 @@ module Plugins::FrontCache::FrontCacheHelper
89
90
 
90
91
  # clear all frontend cache items
91
92
  def front_cache_clean
92
- Rails.cache.clear
93
+ @caches = current_site.get_meta("front_cache_elements")
94
+ if @caches[:invalidate_only]
95
+ @caches[:cache_counter] += 1
96
+ current_site.set_meta("front_cache_elements", @caches)
97
+ else
98
+ Rails.cache.clear
99
+ @caches[:cache_counter] = 0
100
+ current_site.set_meta("front_cache_elements", @caches)
101
+ end
93
102
  end
94
103
 
95
104
  private
96
105
 
97
106
  def front_cache_exist?(key)
98
- !(Rails.cache.read(key).nil?)
107
+ !(Rails.cache.read(front_cache_plugin_get_path(key)).nil?)
99
108
  end
100
109
 
101
110
  def front_cache_get(key)
102
- Rails.cache.read(key)
111
+ Rails.cache.read(front_cache_plugin_get_path(key))
103
112
  end
104
113
 
105
114
  def front_cache_plugin_cache_create(key, content)
@@ -110,9 +119,9 @@ module Plugins::FrontCache::FrontCacheHelper
110
119
  # key: (string, optional) the key of the cached page
111
120
  def front_cache_plugin_get_path(key = nil)
112
121
  unless key.nil?
113
- "pages/#{current_site.id.to_s}/#{key}"
122
+ "pages/#{@caches[:cache_counter]}/#{current_site.id.to_s}/#{key}"
114
123
  else
115
- "pages/#{current_site.id.to_s}"
124
+ "pages/#{@caches[:cache_counter]}/#{current_site.id.to_s}"
116
125
  end
117
126
 
118
127
  end
@@ -20,11 +20,6 @@
20
20
  </div>
21
21
  <div class="panel-body">
22
22
  <div class="alert alert-info"><%= t('plugin.front_cache.message.please_checkpost_need_cache') %></div>
23
- <div class="form-group">
24
- <label>Preserve cache on restart</label><br>
25
- <%= check_box_tag("cache[preserve_cache_on_restart]", 1, @caches[:preserve_cache_on_restart]) %>
26
- </div>
27
-
28
23
  <div class="form-group">
29
24
  <label><%= t('plugin.front_cache.home_page') %></label><br>
30
25
  <%= check_box_tag("cache[home]", 1, @caches[:home]) %>
@@ -61,6 +56,16 @@
61
56
  <%= select_tag("cache[skip_posts]", option_groups_from_collection_for_select(current_site.the_post_types.decorate, :the_posts, 'the_title', "id", lambda{|o| o.decorate.the_title }, @caches[:skip_posts]), "class"=> "form-control select", multiple: true, "data-live-search" => "true") %>
62
57
  </div>
63
58
 
59
+ <div class="form-group">
60
+ <label><%= t('plugin.front_cache.preserve_cache_on_restart') %></label><br>
61
+ <%= check_box_tag("cache[preserve_cache_on_restart]", 1, @caches[:preserve_cache_on_restart]) %>
62
+ </div>
63
+
64
+ <div class="form-group">
65
+ <label><%= t('plugin.front_cache.invalidate_only') %></label><br>
66
+ <%= check_box_tag("cache[invalidate_only]", 1, @caches[:invalidate_only]) %>
67
+ </div>
68
+
64
69
  <!--<div class="form-group">-->
65
70
  <!--<label><%#= t('plugin.front_cache.message.enabled_cache_inner_content_logged_users') %></label><br>-->
66
71
  <!--<%#= check_box_tag("cache[cache_login]", 1, @caches[:cache_login]) %>-->
@@ -7,8 +7,7 @@ class CamaleonCms::Category < CamaleonCms::TermTaxonomy
7
7
  scope :empty, -> { where(count: [0, nil]) } # return all categories that does not contain any post
8
8
  # scope :parents, -> { where("term_taxonomy.parent_id IS NULL") }
9
9
 
10
- has_many :metas, -> { where(object_class: 'Category') }, class_name: 'CamaleonCms::Meta',
11
- foreign_key: :objectid, dependent: :destroy
10
+ cama_define_common_relationships('Category')
12
11
  has_many :posts, foreign_key: :objectid, through: :term_relationships, source: :objects
13
12
  has_many :children, class_name: 'CamaleonCms::Category', foreign_key: :parent_id,
14
13
  dependent: :destroy
@@ -1,7 +1,7 @@
1
1
  class CamaleonCms::NavMenu < CamaleonCms::TermTaxonomy
2
2
  default_scope { where(taxonomy: :nav_menu).order(id: :asc) }
3
3
  alias_attribute :site_id, :parent_id
4
- has_many :metas, ->{ where(object_class: 'NavMenu')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
4
+ cama_define_common_relationships('NavMenu')
5
5
  has_many :children, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, dependent: :destroy, inverse_of: :parent
6
6
  belongs_to :site, :class_name => "CamaleonCms::Site", foreign_key: :parent_id, inverse_of: :nav_menus
7
7
 
@@ -6,7 +6,7 @@ class CamaleonCms::NavMenuItem < CamaleonCms::TermTaxonomy
6
6
  alias_attribute :target, :status
7
7
  # attr_accessible :label, :url, :kind
8
8
  default_scope { where(taxonomy: :nav_menu_item).order(id: :asc) }
9
- has_many :metas, ->{ where(object_class: 'NavMenuItem')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
9
+ cama_define_common_relationships('NavMenuItem')
10
10
  belongs_to :parent, class_name: "CamaleonCms::NavMenu", inverse_of: :children
11
11
  belongs_to :parent_item, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, inverse_of: :children
12
12
  has_many :children, class_name: "CamaleonCms::NavMenuItem", foreign_key: :parent_id, dependent: :destroy, inverse_of: :parent_item
@@ -5,8 +5,7 @@ class CamaleonCms::Plugin < CamaleonCms::TermTaxonomy
5
5
  # name => plugin name
6
6
 
7
7
  attr_accessor :error
8
-
9
- has_many :metas, -> { where(object_class: 'Plugin') }, class_name: "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
8
+ cama_define_common_relationships('Plugin')
10
9
  belongs_to :site, class_name: "CamaleonCms::Site", foreign_key: :parent_id
11
10
 
12
11
  default_scope { where(taxonomy: :plugin) }
@@ -29,7 +29,7 @@ class CamaleonCms::Post < CamaleonCms::PostDefault
29
29
  include CamaleonCms::CategoriesTagsForPosts
30
30
  alias_attribute :post_type_id, :taxonomy_id
31
31
  default_scope ->{ where(post_class: "Post").order(post_order: :asc, created_at: :desc) }
32
- has_many :metas, ->{ where(object_class: 'Post')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :delete_all
32
+ cama_define_common_relationships('Post')
33
33
 
34
34
  # DEPRECATED
35
35
  has_many :post_relationships, class_name: "CamaleonCms::PostRelationship", foreign_key: :objectid, dependent: :destroy, inverse_of: :posts
@@ -7,7 +7,7 @@ class CamaleonCms::PostComment < ActiveRecord::Base
7
7
  #default_scope order('comments.created_at ASC')
8
8
  #approved: approved | pending | spam
9
9
 
10
- has_many :metas, ->{ where(object_class: 'PostComment')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
10
+ cama_define_common_relationships('PostComment')
11
11
  has_many :children, class_name: "CamaleonCms::PostComment", foreign_key: :comment_parent, dependent: :destroy
12
12
  belongs_to :post, class_name: "CamaleonCms::Post", foreign_key: :post_id
13
13
  belongs_to :parent, class_name: "CamaleonCms::PostComment", foreign_key: :comment_parent
@@ -1,6 +1,6 @@
1
1
  class CamaleonCms::PostTag < CamaleonCms::TermTaxonomy
2
2
  default_scope { where(taxonomy: :post_tag) }
3
- has_many :metas, ->{ where(object_class: 'PostTag')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
3
+ cama_define_common_relationships('PostTag')
4
4
  has_many :posts, foreign_key: :objectid, through: :term_relationships, :source => :objects
5
5
  belongs_to :post_type, class_name: "CamaleonCms::PostType", foreign_key: :parent_id, inverse_of: :post_tags
6
6
  belongs_to :owner, class_name: PluginRoutes.static_system_info['user_model'].presence || 'CamaleonCms::User', foreign_key: :user_id
@@ -1,7 +1,7 @@
1
1
  class CamaleonCms::PostType < CamaleonCms::TermTaxonomy
2
2
  alias_attribute :site_id, :parent_id
3
3
  default_scope { where(taxonomy: :post_type) }
4
- has_many :metas, ->{ where(object_class: 'PostType')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :delete_all
4
+ cama_define_common_relationships('PostType')
5
5
  has_many :categories, :class_name => "CamaleonCms::Category", foreign_key: :parent_id, dependent: :destroy, inverse_of: :post_type_parent
6
6
  has_many :post_tags, :class_name => "CamaleonCms::PostTag", foreign_key: :parent_id, dependent: :destroy, inverse_of: :post_type
7
7
  has_many :posts, class_name: "CamaleonCms::Post", foreign_key: :taxonomy_id, dependent: :destroy, inverse_of: :post_type
@@ -3,7 +3,7 @@ class CamaleonCms::Site < CamaleonCms::TermTaxonomy
3
3
  attr_accessor :site_domain
4
4
  include CamaleonCms::SiteDefaultSettings
5
5
  default_scope { where(taxonomy: :site).reorder(term_group: :desc) }
6
- has_many :metas, -> { where(object_class: 'Site') }, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :delete_all
6
+ cama_define_common_relationships('Site')
7
7
  has_many :post_types, :class_name => "CamaleonCms::PostType", foreign_key: :parent_id, dependent: :destroy
8
8
  has_many :nav_menus, :class_name => "CamaleonCms::NavMenu", foreign_key: :parent_id, dependent: :destroy, inverse_of: :site
9
9
  has_many :nav_menu_items, :class_name => "CamaleonCms::NavMenuItem", foreign_key: :term_group
@@ -1,7 +1,7 @@
1
1
  class CamaleonCms::Theme < CamaleonCms::TermTaxonomy
2
2
  # attrs:
3
3
  # slug => plugin key
4
- has_many :metas, -> { where(object_class: 'Theme') }, class_name: "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
4
+ cama_define_common_relationships('Theme')
5
5
  belongs_to :site, class_name: "CamaleonCms::Site", foreign_key: :parent_id
6
6
 
7
7
  default_scope { where(taxonomy: :theme) }
@@ -2,7 +2,7 @@ class CamaleonCms::UserRole < CamaleonCms::TermTaxonomy
2
2
  after_destroy :set_users_as_cilent
3
3
 
4
4
  default_scope { where(taxonomy: :user_roles) }
5
- has_many :metas, ->{ where(object_class: 'UserRole')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
5
+ cama_define_common_relationships('UserRole')
6
6
  belongs_to :site, :class_name => "CamaleonCms::Site", foreign_key: :parent_id
7
7
 
8
8
  def roles_post_type
@@ -1,11 +1,11 @@
1
1
  module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
2
2
  included do
3
3
  before_destroy :_destroy_custom_field_groups
4
+ # DEPRECATED, INSTEAD USE: custom_fields
4
5
  has_many :fields, ->(object){ where(:object_class => object.class.to_s.gsub("Decorator","").gsub("CamaleonCms::",""))} , :class_name => "CamaleonCms::CustomField" ,foreign_key: :objectid
6
+ # DEPRECATED, INSTEAD USE: custom_field_values
5
7
  has_many :field_values, ->(object){where(object_class: object.class.to_s.gsub("Decorator","").gsub("CamaleonCms::",""))}, :class_name => "CamaleonCms::CustomFieldsRelationship", foreign_key: :objectid, dependent: :delete_all
6
- has_many :custom_field_values, ->(object){ where(object_class: object.class.to_s.gsub("Decorator","").gsub("CamaleonCms::", ""))}, :class_name => "CamaleonCms::CustomFieldsRelationship", foreign_key: :objectid, dependent: :delete_all
7
-
8
- # valid only for simple groups and not for complex like: posts, post, ... where the group is for individual or children groups
8
+ # DEPRECATED, INSTEAD USE: custom_field_groups
9
9
  has_many :field_groups, ->(object){where(object_class: object.class.to_s.parseCamaClass)}, :class_name => "CamaleonCms::CustomFieldGroup", foreign_key: :objectid
10
10
  end
11
11
 
@@ -35,12 +35,12 @@ module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
35
35
  when 'Post'
36
36
  CamaleonCms::CustomFieldGroup.where("(objectid = ? AND object_class = ?) OR (objectid = ? AND object_class = ?)", self.id || -1, class_name, self.post_type.id, "PostType_#{class_name}")
37
37
  when 'NavMenuItem'
38
- self.main_menu.field_groups
38
+ self.main_menu.custom_field_groups
39
39
  when 'PostType'
40
40
  if args[:kind] == "all"
41
41
  CamaleonCms::CustomFieldGroup.where(object_class: ["PostType_Post", "PostType_Post", "PostType_PostTag", "PostType"], objectid: self.id )
42
42
  elsif args[:kind] == "post_type"
43
- self.field_groups
43
+ self.custom_field_groups
44
44
  else
45
45
  CamaleonCms::CustomFieldGroup.where(object_class: "PostType_#{args[:kind]}", objectid: self.id )
46
46
  end
@@ -13,7 +13,7 @@ module CamaleonCms::UserMethods extend ActiveSupport::Concern
13
13
  before_create { generate_token(:auth_token) }
14
14
 
15
15
  # relations
16
- has_many :metas, ->{ where(object_class: 'User')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
16
+ cama_define_common_relationships('User')
17
17
  has_many :all_posts, class_name: "CamaleonCms::Post", foreign_key: :user_id
18
18
  has_many :all_comments, class_name: "CamaleonCms::PostComment"
19
19
 
@@ -45,51 +45,60 @@ ActiveRecord::Associations::CollectionProxy.class_eval do
45
45
  end
46
46
  end
47
47
 
48
+ ActiveSupport.on_load(:active_record) do
49
+ class ActiveRecord::Base
50
+ def self.cama_define_common_relationships(key)
51
+ has_many :metas, -> { where(object_class: key) }, class_name: 'CamaleonCms::Meta', foreign_key: :objectid, dependent: :destroy
52
+ has_many :custom_field_values, ->{ where(object_class: key) }, :class_name => "CamaleonCms::CustomFieldsRelationship", foreign_key: :objectid, dependent: :delete_all
53
+ has_many :custom_fields, ->{ where(:object_class => key)} , :class_name => "CamaleonCms::CustomField" ,foreign_key: :objectid
48
54
 
49
- # add cache_var for models
50
- ActiveRecord::Base.class_eval do
51
- # save cache value for this key
52
- def cama_set_cache(key, val)
53
- @cama_cache_vars ||= {}
54
- @cama_cache_vars[cama_build_cache_key(key)] = val
55
- val
56
- end
55
+ # valid only for simple groups and not for complex like: posts, post, ... where the group is for individual or children groups
56
+ has_many :custom_field_groups, ->{ where(object_class: key) }, :class_name => "CamaleonCms::CustomFieldGroup", foreign_key: :objectid
57
+ end
58
+
59
+ # save cache value for this key
60
+ def cama_set_cache(key, val)
61
+ @cama_cache_vars ||= {}
62
+ @cama_cache_vars[cama_build_cache_key(key)] = val
63
+ val
64
+ end
57
65
 
58
- # remove cache value for this key
59
- def cama_remove_cache(key)
60
- @cama_cache_vars.delete(cama_build_cache_key(key))
61
- end
66
+ # remove cache value for this key
67
+ def cama_remove_cache(key)
68
+ @cama_cache_vars.delete(cama_build_cache_key(key))
69
+ end
62
70
 
63
- # fetch the cache value for this key
64
- def cama_fetch_cache(key)
65
- @cama_cache_vars ||= {}
66
- _key = cama_build_cache_key(key)
67
- if @cama_cache_vars.has_key?(_key)
68
- # puts "*********** using model cache var: #{_key}"
69
- @cama_cache_vars[_key]
70
- else
71
- @cama_cache_vars[_key] = yield
72
- @cama_cache_vars[_key]
71
+ # fetch the cache value for this key
72
+ def cama_fetch_cache(key)
73
+ @cama_cache_vars ||= {}
74
+ _key = cama_build_cache_key(key)
75
+ if @cama_cache_vars.has_key?(_key)
76
+ # puts "*********** using model cache var: #{_key}"
77
+ @cama_cache_vars[_key]
78
+ else
79
+ @cama_cache_vars[_key] = yield
80
+ @cama_cache_vars[_key]
81
+ end
73
82
  end
74
- end
75
83
 
76
- # return the cache value for this key
77
- def cama_get_cache(key)
78
- @cama_cache_vars ||= {}
79
- @cama_cache_vars[cama_build_cache_key(key)] rescue nil
80
- end
84
+ # return the cache value for this key
85
+ def cama_get_cache(key)
86
+ @cama_cache_vars ||= {}
87
+ @cama_cache_vars[cama_build_cache_key(key)] rescue nil
88
+ end
81
89
 
82
- # internal helper to generate cache key
83
- def cama_build_cache_key(key)
84
- _key = "cama_cache_#{self.class.name}_#{self.id}_#{key}"
85
- end
86
-
87
- # check if an attribute was changed
88
- def cama_attr_changed?(attr_name)
89
- if self.methods.include?(:saved_change_to_attribute?)
90
- self.saved_change_to_attribute?(attr_name.to_sym)
91
- else
92
- self.send("#{attr_name}_changed?")
90
+ # internal helper to generate cache key
91
+ def cama_build_cache_key(key)
92
+ _key = "cama_cache_#{self.class.name}_#{self.id}_#{key}"
93
+ end
94
+
95
+ # check if an attribute was changed
96
+ def cama_attr_changed?(attr_name)
97
+ if self.methods.include?(:saved_change_to_attribute?)
98
+ self.saved_change_to_attribute?(attr_name.to_sym)
99
+ else
100
+ self.send("#{attr_name}_changed?")
101
+ end
93
102
  end
94
103
  end
95
104
  end