queue.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. module Import
  2. module OTRS
  3. class Queue
  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. QueueID: :id,
  13. Comment: :note,
  14. }.freeze
  15. def initialize(queue)
  16. import(queue)
  17. end
  18. private
  19. def import(queue)
  20. create_or_update(map(queue))
  21. end
  22. def create_or_update(queue)
  23. return if updated?(queue)
  24. create(queue)
  25. end
  26. def updated?(queue)
  27. @local_queue = Group.find_by(id: queue[:id])
  28. return false if !@local_queue
  29. log "update Group.find_by(id: #{queue[:id]})"
  30. @local_queue.update!(queue)
  31. true
  32. end
  33. def create(queue)
  34. log "add Group.find_by(id: #{queue[:id]})"
  35. @local_queue = Group.new(queue)
  36. @local_queue.id = queue[:id]
  37. @local_queue.save
  38. reset_primary_key_sequence('groups')
  39. end
  40. def map(queue)
  41. {
  42. created_by_id: 1,
  43. updated_by_id: 1,
  44. active: active?(queue),
  45. }
  46. .merge(from_mapping(queue))
  47. end
  48. end
  49. end
  50. end