priority.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. module Import
  3. module OTRS
  4. class Priority
  5. include Import::Helper
  6. include Import::OTRS::Helper
  7. MAPPING = {
  8. ChangeTime: :updated_at,
  9. CreateTime: :created_at,
  10. Name: :name,
  11. ID: :id,
  12. Comment: :note,
  13. }.freeze
  14. def initialize(priority)
  15. import(priority)
  16. end
  17. private
  18. def import(priority)
  19. create_or_update(map(priority))
  20. end
  21. def create_or_update(priority)
  22. return if updated?(priority)
  23. create(priority)
  24. end
  25. def updated?(priority)
  26. @local_priority = ::Ticket::Priority.find_by(id: priority[:id])
  27. return false if !@local_priority
  28. log "update Ticket::Priority.find_by(id: #{priority[:id]})"
  29. @local_priority.update!(priority)
  30. true
  31. end
  32. def create(priority)
  33. log "add Ticket::Priority.find_by(id: #{priority[:id]})"
  34. @local_priority = ::Ticket::Priority.new(priority)
  35. @local_priority.id = priority[:id]
  36. @local_priority.save
  37. reset_primary_key_sequence('ticket_priorities')
  38. end
  39. def ui_color(priority)
  40. return 'high-priority' if ['4 high', '5 very high'].include?(priority['Name'])
  41. return 'low-priority' if ['2 low', '1 very low'].include?(priority['Name'])
  42. nil
  43. end
  44. def ui_icon(priority)
  45. return 'important' if ['4 high', '5 very high'].include?(priority['Name'])
  46. return 'low-priority' if ['2 low', '1 very low'].include?(priority['Name'])
  47. nil
  48. end
  49. def map(priority)
  50. {
  51. created_by_id: 1,
  52. updated_by_id: 1,
  53. ui_color: ui_color(priority),
  54. ui_icon: ui_icon(priority),
  55. active: active?(priority),
  56. }
  57. .merge(from_mapping(priority))
  58. end
  59. end
  60. end
  61. end