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.10.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.10.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.9.3 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.9.2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.9.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.9.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.8.4 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.8.3 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.8.2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.8.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.8.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.7.4 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.7.3 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.7.2 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.7.1 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.7.0 app/commands/decidim/pages/copy_page.rb
decidim-pages-0.6.8 app/commands/decidim/pages/copy_page.rb
decidim-0.6.8 decidim-pages/app/commands/decidim/pages/copy_page.rb
decidim-pages-0.6.7 app/commands/decidim/pages/copy_page.rb
decidim-0.6.7 decidim-pages/app/commands/decidim/pages/copy_page.rb