Sha256: 382218aaa704c9ca6502206b25dc6ff374232fb9bbf3da3166256c587bc981ea

Contents?: true

Size: 763 Bytes

Versions: 13

Compression:

Stored size: 763 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Pages
    # Command that gets called whenever a component's page has to be duplicated.
    # It is need a context with the old component that
    # is going to be duplicated on the new one
    class CopyPage < Decidim::Command
      def initialize(context)
        @context = context
      end

      def call
        Decidim::Pages::Page.transaction do
          pages = Decidim::Pages::Page.where(component: @context[:old_component])
          pages.each do |page|
            Decidim::Pages::Page.create!(component: @context[:new_component], body: page.body)
          end
        end
        broadcast(:ok)
      rescue ActiveRecord::RecordInvalid
        broadcast(:invalid)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-pages-0.29.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.28.4 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.29.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.28.3 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.29.0.rc4 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.29.0.rc3 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.29.0.rc2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.29.0.rc1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.28.2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.28.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.28.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.28.0.rc5 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.28.0.rc4 app/commands/decidim/pages/copy_page.rb