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
|
|
|
|
class State
|
|
|
|
include Import::Helper
|
|
|
|
include Import::OTRS::Helper
|
|
|
|
|
|
|
|
MAPPING = {
|
|
|
|
ChangeTime: :updated_at,
|
|
|
|
CreateTime: :created_at,
|
|
|
|
CreateBy: :created_by_id,
|
|
|
|
ChangeBy: :updated_by_id,
|
|
|
|
Name: :name,
|
|
|
|
ID: :id,
|
|
|
|
ValidID: :active,
|
|
|
|
Comment: :note,
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def initialize(state)
|
|
|
|
import(state)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def import(state)
|
|
|
|
create_or_update(map(state))
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_or_update(state)
|
|
|
|
return if updated?(state)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
create(state)
|
|
|
|
end
|
|
|
|
|
|
|
|
def updated?(state)
|
|
|
|
@local_state = ::Ticket::State.find_by(id: state[:id])
|
|
|
|
return false if !@local_state
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
log "update Ticket::State.find_by(id: #{state[:id]})"
|
2017-09-11 11:16:08 +00:00
|
|
|
@local_state.update!(state)
|
2016-11-25 16:10:37 +00:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(state)
|
|
|
|
log "add Ticket::State.find_by(id: #{state[:id]})"
|
|
|
|
@local_state = ::Ticket::State.new(state)
|
|
|
|
@local_state.id = state[:id]
|
|
|
|
@local_state.save
|
|
|
|
reset_primary_key_sequence('ticket_states')
|
|
|
|
end
|
|
|
|
|
|
|
|
def map(state)
|
|
|
|
{
|
|
|
|
created_by_id: 1,
|
|
|
|
updated_by_id: 1,
|
|
|
|
active: active?(state),
|
|
|
|
state_type_id: state_type_id(state)
|
|
|
|
}
|
|
|
|
.merge(from_mapping(state))
|
|
|
|
end
|
|
|
|
|
|
|
|
def state_type_id(state)
|
|
|
|
map_type(state)
|
|
|
|
::Ticket::StateType.lookup(name: state['TypeName']).id
|
|
|
|
end
|
|
|
|
|
|
|
|
def map_type(state)
|
|
|
|
return if state['TypeName'] != 'pending auto'
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
state['TypeName'] = 'pending action'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|