demarches-normaliennes/app/tasks/maintenance/clean_header_section_options_task.rb
2024-10-23 10:35:07 +02:00

23 lines
805 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
module Maintenance
class CleanHeaderSectionOptionsTask < MaintenanceTasks::Task
# In the rest of PR 10713
# TypeDeChamp options may contain options which are not consistent with the
# type_champ (e.g. a header_section TypeDeChamp which has a
# drop_down_options key/value in its options).
# The aim here is to clean up the options so that only those wich are useful
# for the type_champ in question.
def collection
TypeDeChamp
.where(type_champ: 'header_section')
.where.not(options: {})
.where.not("(SELECT COUNT(*) FROM jsonb_each_text(options)) = 1 AND options ? 'header_section_level'")
end
def process(tdc)
tdc.update(options: tdc.options.slice(:header_section_level))
end
end
end