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.26.10 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.26.9 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.26.8 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.26.7 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.26.5 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.26.4 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.26.3 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.26.2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.26.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.26.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.26.0.rc2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.26.0.rc1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.25.2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.25.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.25.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.25.0.rc4 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.25.0.rc3 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.25.0.rc2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.25.0.rc1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.24.3 app/commands/decidim/pages/copy_page.rb