Sha256: 3d8b339bb563e9a1753270143e3761ee1fa41f1c734d479df7102312a33de8f6
Contents?: true
Size: 1.6 KB
Versions: 28
Compression:
Stored size: 1.6 KB
Contents
# frozen_string_literal: true require_dependency "alchemy/page" module Alchemy class Page < BaseRecord # Handles publishing of pages class Publisher def initialize(page) @page = page end # Copies all currently visible elements to the public version of page # # Creates a new published version if none exists yet and updates # the `published_at` timestamp of the page. # `published_at` is used as a cache key. # # Sends a publish notification to all registered publish targets # def publish!(public_on:) Page.transaction do PageMutex.with_lock!(@page) do version = public_version(public_on) DeleteElements.new(version.elements).call repository = page.draft_version.element_repository ActiveRecord::Base.no_touching do Element.acts_as_list_no_update do repository.visible.not_nested.each.with_index(1) do |element, position| Alchemy::DuplicateElement.new(element, repository: repository).call( page_version_id: version.id, position: position ) end end end page.update(published_at: public_on) end end Alchemy.publish_targets.each { |p| p.perform_later(page) } end private attr_reader :page # Load the pages public version or create one def public_version(public_on) page.public_version || page.versions.create!(public_on: public_on) end end end end
Version data entries
28 entries across 28 versions & 1 rubygems