From c2bdbe62d8b54896f9824ae379c0cf6fba9dbf57 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Tue, 3 Sep 2019 16:06:04 +0200 Subject: [PATCH] Follow-up: Fixed issue #1653: Default value not set for attributes of type input, select, tree_select, richtext, textarea, checkbox. --- app/models/object_manager/attribute.rb | 10 ++++-- ...ault_value_not_set_for_select_input_etc.rb | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20190816091726_issue_1653_default_value_not_set_for_select_input_etc.rb diff --git a/app/models/object_manager/attribute.rb b/app/models/object_manager/attribute.rb index 59df0a108..7f52e74bd 100644 --- a/app/models/object_manager/attribute.rb +++ b/app/models/object_manager/attribute.rb @@ -110,7 +110,7 @@ add a new attribute entry for an object created_at: '2014-06-04 10:00:00', updated_at: '2014-06-04 10:00:00', - force: true + force: true, editable: false, to_migrate: false, to_create: false, @@ -329,8 +329,12 @@ possible types if record[:data_option] != data[:data_option] # do we need a database migration? - if record[:data_option][:maxlength] && data[:data_option][:maxlength] && record[:data_option][:maxlength].to_s != data[:data_option][:maxlength].to_s + %i[maxlength default].each do |option| + next if record[:data_option][option]&.to_s == data[:data_option][option]&.to_s + data[:to_migrate] = true + + break end record[:data_option_new] = data[:data_option] @@ -660,7 +664,7 @@ to send no browser reload event, pass false end if attribute.data_type == 'select' && attribute.data_option[:options] - attribute.data_option[:historical_options] = attribute.data_option[:options] + attribute.data_option[:historical_options] = Hash(attribute.data_option[:historical_options]).merge(attribute.data_option[:options]) end data_type = nil diff --git a/db/migrate/20190816091726_issue_1653_default_value_not_set_for_select_input_etc.rb b/db/migrate/20190816091726_issue_1653_default_value_not_set_for_select_input_etc.rb new file mode 100644 index 000000000..3a91eee46 --- /dev/null +++ b/db/migrate/20190816091726_issue_1653_default_value_not_set_for_select_input_etc.rb @@ -0,0 +1,31 @@ +class Issue1653DefaultValueNotSetForSelectInputEtc < ActiveRecord::Migration[5.2] + def change + # return if it's a new setup + return if !Setting.find_by(name: 'system_init_done') + + ObjectManager::Attribute.all.each do |attribute| + next if !attribute.data_type.match?(/^input|select|tree_select|richtext|textarea|checkbox$/) + next if attribute.data_option[:default].blank? + + ObjectManager::Attribute.add( + object: ObjectLookup.by_id(attribute.object_lookup_id), + name: attribute.name, + display: attribute.display, + data_type: attribute.data_type, + data_option: attribute.data_option, + active: attribute.active, + screens: attribute.screens, + position: attribute.position, + created_by_id: attribute.created_by_id, + updated_by_id: attribute.updated_by_id, + created_at: attribute.created_at, + updated_at: attribute.updated_at, + editable: attribute.editable, + to_migrate: true, + ) + end + + # ATTENTION: this may take a while + ObjectManager::Attribute.migration_execute + end +end