2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
module Import
|
|
|
|
module OTRS
|
|
|
|
module StateFactory
|
|
|
|
extend Import::TransactionFactory
|
|
|
|
|
|
|
|
# rubocop:disable Style/ModuleFunction
|
|
|
|
extend self
|
|
|
|
|
2016-12-20 15:16:09 +00:00
|
|
|
def pre_import_hook(_records, *_args)
|
2016-11-25 16:10:37 +00:00
|
|
|
backup
|
|
|
|
end
|
|
|
|
|
|
|
|
def backup
|
|
|
|
# rename states to handle not uniq issues
|
2017-10-01 12:25:52 +00:00
|
|
|
::Ticket::State.all.each do |state|
|
2020-09-30 09:07:01 +00:00
|
|
|
state.name = "#{state.name}_tmp"
|
2016-11-25 16:10:37 +00:00
|
|
|
state.save
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
2017-02-14 08:59:41 +00:00
|
|
|
|
|
|
|
def import_loop(records, *_args, &import_block)
|
|
|
|
super
|
2017-02-14 17:44:14 +00:00
|
|
|
update_attribute_settings
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_attribute_settings
|
|
|
|
return if Import::OTRS.diff?
|
|
|
|
|
|
|
|
update_attribute
|
|
|
|
update_ticket_attributes
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_attribute
|
|
|
|
update_default_create
|
|
|
|
update_default_follow_up
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_default_create
|
|
|
|
state = ::Ticket::State.find_by(
|
|
|
|
name: Import::OTRS::SysConfigFactory.postmaster_default_lookup(:state_default_create),
|
|
|
|
active: true
|
|
|
|
)
|
|
|
|
return if !state
|
|
|
|
|
|
|
|
state.default_create = true
|
2017-06-28 09:58:46 +00:00
|
|
|
state.save!
|
2017-02-14 17:44:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_default_follow_up
|
|
|
|
state = ::Ticket::State.find_by(
|
|
|
|
name: Import::OTRS::SysConfigFactory.postmaster_default_lookup(:state_default_follow_up),
|
|
|
|
active: true
|
|
|
|
)
|
|
|
|
return if !state
|
|
|
|
|
|
|
|
state.default_follow_up = true
|
2017-06-28 09:58:46 +00:00
|
|
|
state.save!
|
2017-02-14 17:44:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_ticket_attributes
|
2017-02-14 08:59:41 +00:00
|
|
|
update_ticket_state
|
2017-05-16 16:11:36 +00:00
|
|
|
reseed_dependent_objects
|
2017-02-14 08:59:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_ticket_state
|
|
|
|
agent_new = ::Ticket::State.where(
|
2017-11-23 08:09:44 +00:00
|
|
|
state_type_id: ::Ticket::StateType.where.not(name: %w[merged removed])
|
2017-02-14 08:59:41 +00:00
|
|
|
).pluck(:id)
|
|
|
|
|
|
|
|
agent_edit = ::Ticket::State.where(
|
2017-11-23 08:09:44 +00:00
|
|
|
state_type_id: ::Ticket::StateType.where.not(name: %w[new merged removed])
|
2017-02-14 08:59:41 +00:00
|
|
|
).pluck(:id)
|
|
|
|
|
|
|
|
customer_new = ::Ticket::State.where(
|
2017-11-23 08:09:44 +00:00
|
|
|
state_type_id: ::Ticket::StateType.where.not(name: %w[new closed])
|
2017-02-14 08:59:41 +00:00
|
|
|
).pluck(:id)
|
|
|
|
|
|
|
|
customer_edit = ::Ticket::State.where(
|
2017-11-23 08:09:44 +00:00
|
|
|
state_type_id: ::Ticket::StateType.where.not(name: %w[open closed])
|
2017-02-14 08:59:41 +00:00
|
|
|
).pluck(:id)
|
|
|
|
|
|
|
|
ticket_state_id = ::ObjectManager::Attribute.get(
|
|
|
|
object: 'Ticket',
|
|
|
|
name: 'state_id',
|
|
|
|
)
|
|
|
|
|
|
|
|
ticket_state_id[:data_option][:filter] = agent_new
|
|
|
|
ticket_state_id[:screens][:create_middle][:Customer] = customer_new
|
|
|
|
ticket_state_id[:screens][:edit][:Agent] = agent_edit
|
|
|
|
ticket_state_id[:screens][:edit][:Customer] = customer_edit
|
|
|
|
|
|
|
|
update_ticket_attribute(ticket_state_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_ticket_attribute(attribute)
|
|
|
|
::ObjectManager::Attribute.add(
|
|
|
|
object_lookup_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],
|
|
|
|
force: true # otherwise _id as a name is not permitted
|
|
|
|
)
|
|
|
|
end
|
2017-05-16 16:11:36 +00:00
|
|
|
|
|
|
|
def reseed_dependent_objects
|
|
|
|
Overview.reseed
|
|
|
|
Trigger.reseed
|
|
|
|
Macro.reseed
|
|
|
|
|
|
|
|
# we don't have to re-seed the ObjectManager
|
|
|
|
# Attributes since they contain the already
|
|
|
|
# imported DynamicFields which will be lost
|
|
|
|
ObjectManager::Attribute.seed
|
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|