Class: Decidim::Cdtb::Fixes::YouTubeEmbedsFixer
- Defined in:
- lib/decidim/cdtb/fixes/you_tube_embeds_fixer.rb
Overview
Fixes YouTube embeds to Decidim v0.28 format in PROCESSED_MODELS. Only YouTube is supported right now.
Constant Summary collapse
- PROCESSED_MODELS =
{ "Decidim::Meetings::Meeting" => [:description], "Decidim::Debates::Debate" => i[description instructions], "Decidim::StaticPage" => [:content], "Decidim::Pages::Page" => [:body], "Decidim::Assembly" => i[short_description description], "Decidim::ParticipatoryProcess" => i[short_description description], "Decidim::Proposals::Proposal" => i[body] }.freeze
Instance Attribute Summary collapse
-
#num_fixed ⇒ Object
readonly
Returns the value of attribute num_fixed.
Attributes inherited from Task
Instance Method Summary collapse
- #do_execution(context) ⇒ Object
- #end_execution(_ctx) ⇒ Object
-
#initialize ⇒ YouTubeEmbedsFixer
constructor
A new instance of YouTubeEmbedsFixer.
- #prepare_execution(_ctx = nil) ⇒ Object
- #total_items ⇒ Object
Methods inherited from Task
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 ⇒ YouTubeEmbedsFixer
Returns a new instance of YouTubeEmbedsFixer.
19 20 21 22 |
# File 'lib/decidim/cdtb/fixes/you_tube_embeds_fixer.rb', line 19 def initialize = { title: self.class.name } super("FIX YOUTUBE EMBEDS", progress_bar:) end |
Instance Attribute Details
#num_fixed ⇒ Object (readonly)
Returns the value of attribute num_fixed.
24 25 26 |
# File 'lib/decidim/cdtb/fixes/you_tube_embeds_fixer.rb', line 24 def num_fixed @num_fixed end |
Instance Method Details
#do_execution(context) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/decidim/cdtb/fixes/you_tube_embeds_fixer.rb', line 39 def do_execution(context) = context[:progress_bar] PROCESSED_MODELS.each_pair do |model_class_name, attribs| log_task_step("Processing #{model_class_name.pluralize}") model_class= model_class_name.constantize model_class.find_each do |model| Rails.logger.debug("Processing #{model_class_name}[#{model.id}]") attribs.each do |attribute| (model, attribute) end @num_fixed+= 1 if model.changed? model.save!(validate: false) .increment end end end |
#end_execution(_ctx) ⇒ Object
60 61 62 |
# File 'lib/decidim/cdtb/fixes/you_tube_embeds_fixer.rb', line 60 def end_execution(_ctx) log_task_step("#{@num_fixed} embeds fixed") end |
#prepare_execution(_ctx = nil) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/decidim/cdtb/fixes/you_tube_embeds_fixer.rb', line 26 def prepare_execution(_ctx = nil) @num_fixed= @num_items= 0 PROCESSED_MODELS.each_key do |model_class| @num_items+= model_class.constantize.count end log_task_info("Checking #{@num_items} models...") end |
#total_items ⇒ Object
35 36 37 |
# File 'lib/decidim/cdtb/fixes/you_tube_embeds_fixer.rb', line 35 def total_items @num_items end |