Sha256: a65ffa9503dc812a590af7ff0bee8098891699ebbd2a006757108c7fb2647cd4

Contents?: true

Size: 1.04 KB

Versions: 10

Compression:

Stored size: 1.04 KB

Contents

class PagesSweeper < ActionController::Caching::Sweeper

  observe Page

  def after_update(page)
    unless page.layoutpage?
      expire_page(page)
      check_multipage_elements(page)
    end
  end

  def after_destroy(page)
    unless page.layoutpage?
      expire_page(page)
      check_multipage_elements(page)
    end
  end

private

  def check_multipage_elements(page)
    page.elements.each do |element|
      # are their pages beneath mine?
      if !element.to_be_sweeped_pages.detect{ |p| p != page }.nil?
        # yepp! there are more pages then mine
        pages = element.to_be_sweeped_pages.find_all_by_public_and_locked(true, false)
        if !pages.blank?
          # expire current page, even if it's locked
          pages.push(page).each do |page|
            expire_page(page)
          end
        end
      end
    end
  end

  def expire_page(page)
    if multi_language?
      path = "#{page.language_code}/#{page.urlname_was}"
    else
      path = page.urlname_was
    end
    expire_action(path) unless page.do_not_sweep
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
alchemy_cms-2.0.rc6 app/sweepers/pages_sweeper.rb
alchemy_cms-2.0.rc5 app/sweepers/pages_sweeper.rb
alchemy_cms-2.0.rc4 app/sweepers/pages_sweeper.rb
alchemy_cms-2.0.rc3 app/sweepers/pages_sweeper.rb
alchemy_cms-2.0.rc2 app/sweepers/pages_sweeper.rb
alchemy_cms-2.0.rc1 app/sweepers/pages_sweeper.rb
alchemy_cms-2.0.pre5 app/sweepers/pages_sweeper.rb
alchemy_cms-2.0.pre4 app/sweepers/pages_sweeper.rb
alchemy_cms-2.0.pre3 app/sweepers/pages_sweeper.rb
alchemy_cms-2.0.pre2 app/sweepers/pages_sweeper.rb