Sha256: d2c14b832233b45d637f08939ca783f5fb615a56a0b45c4dd81689e3de4605d7

Contents?: true

Size: 762 Bytes

Versions: 63

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Pages
    # Command that gets called whenever a component's page has to be duplicated.
    # It's need a context with the old component that
    # is going to be duplicated on the new one
    class CopyPage < Rectify::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

63 entries across 63 versions & 1 rubygems

Version Path
decidim-pages-0.17.2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.18.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.17.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.16.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.17.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.16.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.15.2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.15.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.15.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.14.4 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.14.3 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.14.2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.14.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.13.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.12.2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.13.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.12.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.13.0.pre1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.12.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.11.2 app/commands/decidim/pages/copy_page.rb