From 1a5df82a1e7a0ffa2938ca338136c851c49e1a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= Date: Fri, 12 Jul 2024 12:24:58 +0200 Subject: [PATCH] refactor options: skip callbacks (#2096) * refactor options: skip callbacks * comment --- app/jobs/refactor_options_job.rb | 90 ++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/app/jobs/refactor_options_job.rb b/app/jobs/refactor_options_job.rb index 31a349f93..65bb997ff 100644 --- a/app/jobs/refactor_options_job.rb +++ b/app/jobs/refactor_options_job.rb @@ -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