priority.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. module Import
  2. module OTRS
  3. class Priority
  4. include Import::Helper
  5. include Import::OTRS::Helper
  6. MAPPING = {
  7. ChangeTime: :updated_at,
  8. CreateTime: :created_at,
  9. CreateBy: :created_by_id,
  10. ChangeBy: :updated_by_id,
  11. Name: :name,
  12. ID: :id,
  13. Comment: :note,
  14. }.freeze
  15. def initialize(priority)
  16. import(priority)
  17. end
  18. private
  19. def import(priority)
  20. create_or_update(map(priority))
  21. end
  22. def create_or_update(priority)
  23. return if updated?(priority)
  24. create(priority)
  25. end
  26. def updated?(priority)
  27. @local_priority = ::Ticket::Priority.find_by(id: priority[:id])
  28. return false if !@local_priority
  29. log "update Ticket::Priority.find_by(id: #{priority[:id]})"
  30. @local_priority.update!(priority)
  31. true
  32. end
  33. def create(priority)
  34. log "add Ticket::Priority.find_by(id: #{priority[:id]})"
  35. @local_priority = ::Ticket::Priority.new(priority)
  36. @local_priority.id = priority[:id]
  37. @local_priority.save
  38. reset_primary_key_sequence('ticket_priorities')
  39. end
  40. def map(priority)
  41. {
  42. created_by_id: 1,
  43. updated_by_id: 1,
  44. active: active?(priority),
  45. }
  46. .merge(from_mapping(priority))
  47. end
  48. end
  49. end
  50. end