Class: Decidim::Cdtb::ParticipatorySpaces::MoveImagesToContentBlock

Inherits:
Task
  • Object
show all
Includes:
ManagesContentBlocks
Defined in:
lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb

Overview

Move images to content block for participatory spaces

Instance Attribute Summary collapse

Attributes inherited from Task

#num_applied, #title

Instance Method Summary collapse

Methods included from ManagesContentBlocks

#current_space_content_blocks, #find_or_create_content_block, #manifest_for, #scope_name, #update_content_block_image

Methods inherited from Task

#execute!, #finish, #init

Methods included from TasksUtils

#do_log_error, #do_log_info, #log_task_end, #log_task_failure, #log_task_info, #log_task_step, #log_task_title, #logger

Constructor Details

#initialize(processed_models) ⇒ MoveImagesToContentBlock

Returns a new instance of MoveImagesToContentBlock.



12
13
14
15
16
# File 'lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb', line 12

def initialize(processed_models)
  progress_bar= { title: self.class.name }
  @processed_models = processed_models
  super("MOVING IMAGES...", progress_bar:)
end

Instance Attribute Details

#num_addedObject (readonly)

Returns the value of attribute num_added.



18
19
20
# File 'lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb', line 18

def num_added
  @num_added
end

Instance Method Details

#do_execution(context) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb', line 33

def do_execution(context)
  progress_bar= context[:progress_bar]

  @processed_models.each do |processed_model|
    log_task_step("Processing #{processed_model}")

    spaces = processed_model

    spaces.find_each do |space|
      image_content_block = find_or_create_content_block(space, "hero")

      next if image_content_block.images.present?

      update_content_block_image(image_content_block, space.banner_image)

      @num_added += 1
      progress_bar.increment
    end
  end
end

#end_execution(_ctx) ⇒ Object



54
55
56
# File 'lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb', line 54

def end_execution(_ctx)
  log_task_step("#{@num_added} content blocks added")
end

#prepare_execution(_ctx = nil) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb', line 20

def prepare_execution(_ctx = nil)
  @num_added= @num_items= 0

  @processed_models.each do |model_name|
    @num_items+= model_name.count
  end
  log_task_info("Moving images to content block in #{@num_items} spaces...")
end

#total_itemsObject



29
30
31
# File 'lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb', line 29

def total_items
  @num_items
end