Class: Pulitzer::UpdatePostTypeContentElements

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptcet, old_label = nil) ⇒ UpdatePostTypeContentElements

Returns a new instance of UpdatePostTypeContentElements.



4
5
6
7
8
# File 'app/interactions/pulitzer/update_post_type_content_elements.rb', line 4

def initialize(ptcet, old_label=nil)
  self.post_type_version  = ptcet.post_type_version
  self.ptcet      = ptcet
  self.old_label  = old_label || ptcet.label
end

Instance Attribute Details

#old_labelObject

Returns the value of attribute old_label.



2
3
4
# File 'app/interactions/pulitzer/update_post_type_content_elements.rb', line 2

def old_label
  @old_label
end

#post_type_versionObject

Returns the value of attribute post_type_version.



2
3
4
# File 'app/interactions/pulitzer/update_post_type_content_elements.rb', line 2

def post_type_version
  @post_type_version
end

#ptcetObject

Returns the value of attribute ptcet.



2
3
4
# File 'app/interactions/pulitzer/update_post_type_content_elements.rb', line 2

def ptcet
  @ptcet
end

Instance Method Details

#callObject



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
# File 'app/interactions/pulitzer/update_post_type_content_elements.rb', line 10

def call
  post_type_version.posts.each do |post|
    begin
      preview_version = post.get_preview_version!
      post.preview_version.content_elements.where(label: old_label).each do |content_element|
        content_element.update(label: ptcet.label,
          height: ptcet.height,
          width: ptcet.width,
          text_editor: ptcet.text_editor,
          content_element_type: ptcet.content_element_type,
          post_type_content_element_type: ptcet)
      end
    rescue Pulitzer::VersionAccessError
      # if there is no preview version, skip this one.
    end
  end
  post_type_version.partials.joins(free_form_section: :version).where(pulitzer_versions: {status: 0}).each do |partial|
    partial.content_elements.where(label: old_label).each do |content_element|
      content_element.update(label: ptcet.label,
        height: ptcet.height,
        width: ptcet.width,
        text_editor: ptcet.text_editor,
        content_element_type: ptcet.content_element_type,
        post_type_content_element_type: ptcet)
    end
  end
end