Sha256: 5f8492dd9496196c7ee7dc3461eb38a52cb506c770e75399963402af25034014

Contents?: true

Size: 750 Bytes

Versions: 56

Compression:

Stored size: 750 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Pages
    # Command that gets called whenever a feature's page has to be duplicated.
    # It's need a context with the old feature 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(feature: @context[:old_feature])
          pages.each do |page|
            Decidim::Pages::Page.create!(feature: @context[:new_feature], body: page.body)
          end
        end
        broadcast(:ok)
      rescue ActiveRecord::RecordInvalid
        broadcast(:invalid)
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 2 rubygems

Version Path
decidim-pages-0.6.6 app/commands/decidim/pages/copy_page.rb
decidim-0.6.6 decidim-pages/app/commands/decidim/pages/copy_page.rb
decidim-pages-0.6.5 app/commands/decidim/pages/copy_page.rb
decidim-0.6.5 decidim-pages/app/commands/decidim/pages/copy_page.rb
decidim-pages-0.6.4 app/commands/decidim/pages/copy_page.rb
decidim-0.6.4 decidim-pages/app/commands/decidim/pages/copy_page.rb
decidim-pages-0.6.3 app/commands/decidim/pages/copy_page.rb
decidim-0.6.3 decidim-pages/app/commands/decidim/pages/copy_page.rb
decidim-pages-0.6.2 app/commands/decidim/pages/copy_page.rb
decidim-0.6.2 decidim-pages/app/commands/decidim/pages/copy_page.rb
decidim-pages-0.6.1 app/commands/decidim/pages/copy_page.rb
decidim-0.6.1 decidim-pages/app/commands/decidim/pages/copy_page.rb
decidim-pages-0.6.0 app/commands/decidim/pages/copy_page.rb
decidim-0.6.0 decidim-pages/app/commands/decidim/pages/copy_page.rb
decidim-pages-0.5.1 app/commands/decidim/pages/copy_page.rb
decidim-0.5.1 decidim-pages/app/commands/decidim/pages/copy_page.rb
decidim-pages-0.5.0 app/commands/decidim/pages/copy_page.rb
decidim-0.5.0 decidim-pages/app/commands/decidim/pages/copy_page.rb
decidim-pages-0.4.4 app/commands/decidim/pages/copy_page.rb
decidim-0.4.4 decidim-pages/app/commands/decidim/pages/copy_page.rb