Sha256: b3064d8d64f596c27874d0f3b2bcab50b8b6abe801464eb998df9761bc0dfda7

Contents?: true

Size: 1.51 KB

Versions: 9

Compression:

Stored size: 1.51 KB

Contents

class Pulitzer::CloneVersion
  include Pulitzer::Engine.routes.url_helpers

  def initialize(version)
    @version = version
    @post = @version.post
    Rails.logger.info("Pulitzer::CloneVersion !!! ")
    Rails.logger.info($0)
  end

  def call
    new_version = @post.processing_version
    cloning_errors = []
    new_version.processed_element_count = 0
    @version.content_elements.each do |ce|
      begin
        cloned_content_element = ce.clone_me
        new_version.content_elements << cloned_content_element
      rescue ActiveRecord::RecordInvalid => invalid
        cloning_errors.push "ContentElement #{ce.id} could not be cloned: #{invalid.record.errors.full_messages.join(', ')}"
      end
      new_version.processed_element_count += 1
      new_version.broadcast_change if defined? ForeignOffice
    end
    @version.post_tags.each do |pt|
      new_version.post_tags << pt.clone_me
      new_version.processed_element_count += 1
      new_version.broadcast_change if defined? ForeignOffice
    end
    if cloning_errors.any?
      new_version.update(status: :processing_failed, cloning_errors: cloning_errors)
    else
      new_version.update(status: :preview)
      new_version.processed_element_count += 1
      new_version.broadcast_change if defined? ForeignOffice
    end
    @post.new_preview_version = edit_version_path(new_version)
    new_version.processed_element_count += 1
    new_version.broadcast_change if defined? ForeignOffice
    @post.broadcast_change if defined? ForeignOffice
    new_version
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pulitzer-0.3.9 app/interactions/pulitzer/clone_version.rb
pulitzer-0.3.8 app/interactions/pulitzer/clone_version.rb
pulitzer-0.3.7 app/interactions/pulitzer/clone_version.rb
pulitzer-0.3.6 app/interactions/pulitzer/clone_version.rb
pulitzer-0.3.5 app/interactions/pulitzer/clone_version.rb
pulitzer-0.3.4 app/interactions/pulitzer/clone_version.rb
pulitzer-0.3.3 app/interactions/pulitzer/clone_version.rb
pulitzer-0.3.1 app/interactions/pulitzer/clone_version.rb
pulitzer-0.3.0 app/interactions/pulitzer/clone_version.rb