Class: Pulitzer::PostTypeVersionsController::Clone

Inherits:
Object
  • Object
show all
Defined in:
app/interactions/pulitzer/post_type_versions_controller/clone.rb

Instance Method Summary collapse

Constructor Details

#initialize(post_type_version) ⇒ Clone

Returns a new instance of Clone.



4
5
6
# File 'app/interactions/pulitzer/post_type_versions_controller/clone.rb', line 4

def initialize(post_type_version)
  @post_type_version = post_type_version
end

Instance Method Details

#add_post_type_error(message) ⇒ Object



73
74
75
# File 'app/interactions/pulitzer/post_type_versions_controller/clone.rb', line 73

def add_post_type_error(message)
  @post_type_version.processing_failed!
end

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/interactions/pulitzer/post_type_versions_controller/clone.rb', line 8

def call
  published_type_version = @post_type_version.post_type.published_type_version
  @post_type_version.processed_element_count = 1
  published_type_version.post_type_content_element_types.each do |ptcet|
    begin
      @post_type_version.post_type_content_element_types << ptcet.clone_me
    rescue ActiveRecord::RecordInvalid => invalid
      error_message = "PostType Content Element Type #{ptcet.id} could not be cloned: #{invalid.record.errors.full_messages.join(', ')}"
      add_post_type_error(error_message)
    end
  end
  if @post_type_version.kind == 'partial'
    published_type_version.background_styles.each do |bs|
      begin
        @post_type_version.background_styles << bs.clone_me
      rescue ActiveRecord::RecordInvalid => invalid
        error_message = "Background Styles #{bs.id} could not be cloned: #{invalid.record.errors.full_messages.join(', ')}"
        add_post_type_error(error_message)
      end
    end
    published_type_version.justification_styles.each do |js|
      begin
        @post_type_version.justification_styles << js.clone_me
      rescue ActiveRecord::RecordInvalid => invalid
        error_message = "Justification Styles #{js.id} could not be cloned: #{invalid.record.errors.full_messages.join(', ')}"
        add_post_type_error(error_message)
      end
    end
    published_type_version.sequence_flow_styles.each do |sfs|
      begin
        @post_type_version.sequence_flow_styles << sfs.clone_me
      rescue ActiveRecord::RecordInvalid => invalid
        error_message = "Sequence Flow Styles #{sfs.id} could not be cloned: #{invalid.record.errors.full_messages.join(', ')}"
        add_post_type_error(error_message)
      end
    end
    published_type_version.arrangement_styles.each do |as|
      begin
        @post_type_version.arrangement_styles << as.clone_me
      rescue ActiveRecord::RecordInvalid => invalid
        error_message = "Arrangement Styles #{as.id} could not be cloned: #{invalid.record.errors.full_messages.join(', ')}"
        add_post_type_error(error_message)
      end
    end
  elsif @post_type_version.kind == 'template'
    published_type_version.free_form_section_types.each do |ffst|
      begin
        @post_type_version.free_form_section_types << ffst.clone_me
      rescue ActiveRecord::RecordInvalid => invalid
        error_message = "Free Form Section Type #{ffst.id} could not be cloned: #{invalid.record.errors.full_messages.join(', ')}"
        add_post_type_error(error_message)
      end
    end
    published_type_version.posts.each do |post|
      Pulitzer::PostTypeVersionsController::ClonePostWithVersionElements.new(post, @post_type_version).call
      @post_type_version.processed_element_count += 1
      @post_type_version.broadcast_change if defined? ForeignOffice
    end
  end
  @post_type_version.finished_processing = post_type_version_path(@post_type_version)
  @post_type_version.broadcast_change if defined? ForeignOffice
  @post_type_version
end