From 9d7b377652b0e80745b7af772889de9eba162967 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 23 Oct 2017 02:16:29 +0200 Subject: [PATCH] Improved store migration for channel.options with multi mixed content. --- .../20170910000001_fixed_store_upgrade_45.rb | 17 --------- ...171023000001_fixed_store_upgrade_ror_45.rb | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 17 deletions(-) delete mode 100644 db/migrate/20170910000001_fixed_store_upgrade_45.rb create mode 100644 db/migrate/20171023000001_fixed_store_upgrade_ror_45.rb diff --git a/db/migrate/20170910000001_fixed_store_upgrade_45.rb b/db/migrate/20170910000001_fixed_store_upgrade_45.rb deleted file mode 100644 index 8df1273e1..000000000 --- a/db/migrate/20170910000001_fixed_store_upgrade_45.rb +++ /dev/null @@ -1,17 +0,0 @@ -class FixedStoreUpgrade45 < ActiveRecord::Migration[5.0] - def up - - # return if it's a new setup - return if !Setting.find_by(name: 'system_init_done') - Cache.clear - [Macro, Taskbar, Calendar, Trigger, Channel, Job, PostmasterFilter, Report::Profile, Setting, Sla, Template].each do |class_name| - class_name.all.each do |record| - begin - record.save! - rescue => e - Rails.logger.error "Unable to save/update #{class_name}.find(#{record.id}): #{e.message}" - end - end - end - end -end diff --git a/db/migrate/20171023000001_fixed_store_upgrade_ror_45.rb b/db/migrate/20171023000001_fixed_store_upgrade_ror_45.rb new file mode 100644 index 000000000..efa85d8d5 --- /dev/null +++ b/db/migrate/20171023000001_fixed_store_upgrade_ror_45.rb @@ -0,0 +1,37 @@ +class FixedStoreUpgradeRor45 < ActiveRecord::Migration[5.0] + def up + + # return if it's a new setup + return if !Setting.find_by(name: 'system_init_done') + Cache.clear + [Macro, Taskbar, Calendar, Trigger, Channel, Job, PostmasterFilter, Report::Profile, Setting, Sla, Template].each do |class_name| + class_name.all.each do |record| + begin + record.save! + rescue => e + Rails.logger.error "Unable to save/update #{class_name}.find(#{record.id}): #{e.message}" + end + end + end + + Channel.all.each do |channel| + channel = Channel.last + next if channel.options.blank? + channel.options.each do |key, value| + channel.options[key] = cleanup(value) + end + channel.save! + end + end + + def cleanup(value) + if value.class == ActionController::Parameters + value = value.permit!.to_h + end + return value if value.class != ActiveSupport::HashWithIndifferentAccess && value.class != Hash + value.each do |local_key, local_value| + value[local_key] = cleanup(local_value) + end + value + end +end