2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
module Import
|
|
|
|
module OTRS
|
|
|
|
class Priority
|
|
|
|
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,
|
|
|
|
Comment: :note,
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def initialize(priority)
|
|
|
|
import(priority)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def import(priority)
|
|
|
|
create_or_update(map(priority))
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_or_update(priority)
|
|
|
|
return if updated?(priority)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
create(priority)
|
|
|
|
end
|
|
|
|
|
|
|
|
def updated?(priority)
|
|
|
|
@local_priority = ::Ticket::Priority.find_by(id: priority[:id])
|
|
|
|
return false if !@local_priority
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
log "update Ticket::Priority.find_by(id: #{priority[:id]})"
|
2017-09-11 11:16:08 +00:00
|
|
|
@local_priority.update!(priority)
|
2016-11-25 16:10:37 +00:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(priority)
|
|
|
|
log "add Ticket::Priority.find_by(id: #{priority[:id]})"
|
|
|
|
@local_priority = ::Ticket::Priority.new(priority)
|
|
|
|
@local_priority.id = priority[:id]
|
|
|
|
@local_priority.save
|
|
|
|
reset_primary_key_sequence('ticket_priorities')
|
|
|
|
end
|
|
|
|
|
2020-03-24 17:54:45 +00:00
|
|
|
def ui_color(priority)
|
|
|
|
return 'high-priority' if ['4 high', '5 very high'].include?(priority['Name'])
|
2020-03-25 12:11:59 +00:00
|
|
|
return 'low-priority' if ['2 low', '1 very low'].include?(priority['Name'])
|
2020-03-24 17:54:45 +00:00
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def ui_icon(priority)
|
|
|
|
return 'important' if ['4 high', '5 very high'].include?(priority['Name'])
|
2020-03-25 12:11:59 +00:00
|
|
|
return 'low-priority' if ['2 low', '1 very low'].include?(priority['Name'])
|
2020-03-24 17:54:45 +00:00
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
def map(priority)
|
|
|
|
{
|
|
|
|
created_by_id: 1,
|
|
|
|
updated_by_id: 1,
|
2020-03-24 17:54:45 +00:00
|
|
|
ui_color: ui_color(priority),
|
|
|
|
ui_icon: ui_icon(priority),
|
2016-11-25 16:10:37 +00:00
|
|
|
active: active?(priority),
|
|
|
|
}
|
|
|
|
.merge(from_mapping(priority))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|