Improved zendesk field migration, mapped checkbox to boolean.
This commit is contained in:
parent
5aa51f82a6
commit
e8b906c1cf
4 changed files with 41 additions and 37 deletions
|
@ -1,6 +1,13 @@
|
|||
|
||||
class EmailTicketCcRemove < ActiveRecord::Migration
|
||||
def up
|
||||
ObjectManager::Attribute.remove(object: 'Ticket', name: 'cc', force: true)
|
||||
# return if it's a new setup
|
||||
return if !Setting.find_by(name: 'system_init_done')
|
||||
object_lookup_id = ObjectLookup.by_name('Ticket')
|
||||
record = ObjectManager::Attribute.find_by(
|
||||
object_lookup_id: object_lookup_id,
|
||||
name: 'cc',
|
||||
)
|
||||
record.destroy if record
|
||||
end
|
||||
end
|
||||
|
|
|
@ -343,63 +343,51 @@ module Import::Zendesk
|
|||
}
|
||||
|
||||
if zendesk_field.type == 'date'
|
||||
|
||||
data_option = {
|
||||
future: true,
|
||||
past: true,
|
||||
diff: 0,
|
||||
}.merge( data_option )
|
||||
|
||||
}.merge(data_option)
|
||||
elsif zendesk_field.type == 'checkbox'
|
||||
|
||||
data_type = 'checkbox'
|
||||
data_type = 'boolean'
|
||||
data_option = {
|
||||
type: zendesk_field.type,
|
||||
default: '',
|
||||
options: {},
|
||||
}.merge( data_option )
|
||||
|
||||
default: false,
|
||||
options: {
|
||||
true => 'yes',
|
||||
false => 'no',
|
||||
},
|
||||
}.merge(data_option)
|
||||
elsif zendesk_field.type == 'regexp'
|
||||
|
||||
data_type = 'input'
|
||||
data_option = {
|
||||
type: 'text',
|
||||
maxlength: 255,
|
||||
regex: zendesk_field.regexp_for_validation,
|
||||
}.merge( data_option )
|
||||
|
||||
}.merge(data_option)
|
||||
elsif zendesk_field.type == 'decimal'
|
||||
|
||||
data_type = 'input'
|
||||
data_option = {
|
||||
type: 'text',
|
||||
maxlength: 255,
|
||||
}.merge( data_option )
|
||||
|
||||
}.merge(data_option)
|
||||
elsif zendesk_field.type == 'integer'
|
||||
|
||||
data_type = 'integer'
|
||||
data_option = {
|
||||
min: 0,
|
||||
max: 999_999_999,
|
||||
}.merge( data_option )
|
||||
|
||||
}.merge(data_option)
|
||||
elsif zendesk_field.type == 'text'
|
||||
|
||||
data_type = 'input'
|
||||
data_option = {
|
||||
type: zendesk_field.type,
|
||||
maxlength: 255,
|
||||
}.merge( data_option )
|
||||
|
||||
}.merge(data_option)
|
||||
elsif zendesk_field.type == 'textarea'
|
||||
|
||||
data_type = 'input'
|
||||
data_option = {
|
||||
type: zendesk_field.type,
|
||||
maxlength: 255,
|
||||
}.merge( data_option )
|
||||
|
||||
}.merge(data_option)
|
||||
elsif zendesk_field.type == 'tagger' || zendesk_field.type == 'dropdown'
|
||||
|
||||
# \"custom_field_options\"=>[{\"id\"=>28353445
|
||||
|
@ -432,7 +420,7 @@ module Import::Zendesk
|
|||
data_option = {
|
||||
default: '',
|
||||
options: options,
|
||||
}.merge( data_option )
|
||||
}.merge(data_option)
|
||||
end
|
||||
|
||||
screens = {
|
||||
|
@ -1064,10 +1052,11 @@ module Import::Zendesk
|
|||
custom_fields.each { |custom_field|
|
||||
field_name = @zendesk_field_mapping[ custom_field['id'] ].gsub(/\s/, '_')
|
||||
field_value = custom_field['value']
|
||||
next if field_value.nil? # ignore nil values
|
||||
if @zendesk_ticket_field_value_mapping[ field_name ]
|
||||
field_value = @zendesk_ticket_field_value_mapping[ field_name ][ field_value ]
|
||||
end
|
||||
fields[ field_name ] = field_value
|
||||
fields[ field_name.to_sym ] = field_value
|
||||
}
|
||||
fields
|
||||
end
|
||||
|
|
|
@ -288,11 +288,11 @@ class ZendeskImportTest < ActiveSupport::TestCase
|
|||
owner_id: 1,
|
||||
customer_id: 6,
|
||||
organization_id: 2,
|
||||
test_checkbox: 'f',
|
||||
test_checkbox: true,
|
||||
custom_integer: 999,
|
||||
custom_dropdown: 'key2',
|
||||
custom_decimal: '1.6',
|
||||
not_existing: nil,
|
||||
custom_decimal: '1.6',
|
||||
not_existing: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -310,12 +310,12 @@ If you\'re reading this message in your email, click the ticket number link that
|
|||
priority_id: 1,
|
||||
owner_id: 1,
|
||||
customer_id: 7,
|
||||
organization_id: nil,
|
||||
test_checkbox: 'f',
|
||||
custom_integer: nil,
|
||||
custom_dropdown: '',
|
||||
custom_decimal: nil,
|
||||
not_existing: nil,
|
||||
organization_id: nil,
|
||||
test_checkbox: false,
|
||||
custom_integer: nil,
|
||||
custom_dropdown: '',
|
||||
custom_decimal: nil,
|
||||
not_existing: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
@ -10,6 +10,8 @@ class ObjectManagerTest < ActiveSupport::TestCase
|
|||
list_objects = ObjectManager.list_frontend_objects
|
||||
assert_equal(%w(Ticket User Organization Group), list_objects)
|
||||
|
||||
assert_equal(false, ObjectManager::Attribute.pending_migration?)
|
||||
|
||||
# create simple attribute
|
||||
attribute1 = ObjectManager::Attribute.add(
|
||||
object: 'Ticket',
|
||||
|
@ -55,6 +57,12 @@ class ObjectManagerTest < ActiveSupport::TestCase
|
|||
name: 'test1',
|
||||
)
|
||||
|
||||
attribute1 = ObjectManager::Attribute.get(
|
||||
object: 'Ticket',
|
||||
name: 'test1',
|
||||
)
|
||||
assert_not(attribute1)
|
||||
|
||||
assert_equal(false, ObjectManager::Attribute.pending_migration?)
|
||||
assert(ObjectManager::Attribute.migration_execute)
|
||||
|
||||
|
|
Loading…
Reference in a new issue