class Decidim::Pages::CopyPage

is going to be duplicated on the new one
It is need a context with the old component that
Command that gets called whenever a component’s page has to be duplicated.

def call

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

def initialize(context)

def initialize(context)
  @context = context
end