queue.rb 1.3 KB

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