app/models/page.rb in refinerycms-pages-0.9.9.8 vs app/models/page.rb in refinerycms-pages-0.9.9.9
- old
+ new
@@ -25,23 +25,26 @@
# Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
acts_as_indexed :fields => [:title, :meta_keywords, :meta_description,
:custom_title, :browser_title, :all_page_part_content]
before_destroy :deletable?
- after_save :reposition_parts!
- after_save :invalidate_child_cached_url
+ after_save :reposition_parts!, :invalidate_child_cached_url, :expire_page_caching
+ after_destroy :expire_page_caching
scope :live, where(:draft => false)
+ scope :by_title, lambda {|t|
+ where(:id => Page::Translation.where(:locale => Globalize.locale, :title => t).map(&:page_id))
+ }
- # shows all pages with :show_in_menu set to true, but it also
+ # Shows all pages with :show_in_menu set to true, but it also
# rejects any page that has not been translated to the current locale.
+ # This works using a query against the translated content first and then
+ # using all of the page_ids we further filter against this model's table.
scope :in_menu, lambda {
- pages = Arel::Table.new(Page.table_name)
- translations = Arel::Table.new(Page.translations_table_name)
-
- includes(:translations).where(:show_in_menu => true).where(
- translations[:locale].eq(Globalize.locale)).where(pages[:id].eq(translations[:page_id]))
+ where(:show_in_menu => true).joins(:translations).includes(:translations).where(
+ :id => Page::Translation.where(:locale => Globalize.locale).map(&:page_id)
+ )
}
# when a dialog pops up to link to a page, how many pages per page should there be
PAGES_PER_DIALOG = 14
@@ -124,10 +127,12 @@
with_locale_param url_normal
end
end
def link_url_localised?
+ return link_url unless defined?(::Refinery::I18n)
+
current_url = link_url
if current_url =~ %r{^/} && ::Refinery::I18n.current_frontend_locale != ::Refinery::I18n.default_frontend_locale
current_url = "/#{::Refinery::I18n.current_frontend_locale}#{current_url}"
end
@@ -229,10 +234,16 @@
end
def use_marketable_urls?
RefinerySetting.find_or_set(:use_marketable_urls, true, :scoping => 'pages')
end
+
+ def expire_page_caching
+ if File.writable?(Rails.cache.cache_path)
+ Pathname.glob(File.join(Rails.cache.cache_path, '**', '*pages*')).each(&:delete)
+ end
+ end
end
# Accessor method to get a page part from a page.
# Example:
#
@@ -280,16 +291,20 @@
sluggified << "-page"
end
sluggified
end
- private
+private
def invalidate_child_cached_url
return true unless self.class.use_marketable_urls?
children.each do |child|
Rails.cache.delete(child.url_cache_key)
Rails.cache.delete(child.path_cache_key)
end
+ end
+
+ def expire_page_caching
+ self.class.expire_page_caching
end
end