Skip to content

Commit

Permalink
refactor options: skip callbacks (#2096)
Browse files Browse the repository at this point in the history
* refactor options: skip callbacks

* comment
  • Loading branch information
SebouChu committed Jul 12, 2024
1 parent 61634b3 commit 1a5df82
Showing 1 changed file with 51 additions and 39 deletions.
90 changes: 51 additions & 39 deletions app/jobs/refactor_options_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,57 @@ class RefactorOptionsJob < ApplicationJob
queue_as :default

def perform
# Options
Communication::Block.agenda.find_each do |block|
template = block.template
template.option_categories = template.show_category
template.option_summary = template.show_summary
template.option_status = template.show_status
block.save
end
Communication::Block.organizations.find_each do |block|
template = block.template
template.option_link = template.with_link
block.save
end
Communication::Block.pages.find_each do |block|
template = block.template
template.option_image = template.show_image
template.option_summary = template.show_description
template.option_main_summary = template.show_main_description
block.save
end
Communication::Block.persons.find_each do |block|
template = block.template
template.option_image = template.with_photo
template.option_link = template.with_link
block.save
end
Communication::Block.posts.find_each do |block|
template = block.template
template.option_author = !template.hide_author
template.option_categories = !template.hide_category
template.option_date = !template.hide_date
template.option_image = !template.hide_image
template.option_summary = !template.hide_summary
block.save
end
# Headings (pas de lien avec les options)
Communication::Block::Heading.where(slug: nil).find_each do |heading|
heading.set_slug
heading.update_column :slug, heading.slug
begin
# Skip callbacks
Communication::Block.skip_callback :save, :after, :touch_about
Communication::Block.skip_callback :save, :after, :connect_and_sync_direct_sources
Communication::Block.skip_callback :save, :after, :clean_websites_if_necessary

# Options
Communication::Block.agenda.find_each do |block|
template = block.template
template.option_categories = template.show_category
template.option_summary = template.show_summary
template.option_status = template.show_status
block.save
end
Communication::Block.organizations.find_each do |block|
template = block.template
template.option_link = template.with_link
block.save
end
Communication::Block.pages.find_each do |block|
template = block.template
template.option_image = template.show_image
template.option_summary = template.show_description
template.option_main_summary = template.show_main_description
block.save
end
Communication::Block.persons.find_each do |block|
template = block.template
template.option_image = template.with_photo
template.option_link = template.with_link
block.save
end
Communication::Block.posts.find_each do |block|
template = block.template
template.option_author = !template.hide_author
template.option_categories = !template.hide_category
template.option_date = !template.hide_date
template.option_image = !template.hide_image
template.option_summary = !template.hide_summary
block.save
end
# Headings (pas de lien avec les options)
Communication::Block::Heading.where(slug: nil).find_each do |heading|
heading.set_slug
heading.update_column :slug, heading.slug
end
ensure
# Re-set callbacks
Communication::Block.set_callback :save, :after, :clean_websites_if_necessary
Communication::Block.set_callback :save, :after, :connect_and_sync_direct_sources
Communication::Block.set_callback :save, :after, :touch_about
end
end
end

0 comments on commit 1a5df82

Please sign in to comment.