attachments.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
  2. class Sequencer
  3. class Unit
  4. module Import
  5. module Zendesk
  6. module Ticket
  7. module Comment
  8. class Attachments < Sequencer::Unit::Import::Zendesk::SubSequence::SubObject
  9. def process
  10. # check if we need to import the attachments
  11. return if skip?
  12. # if so call the original .process from SubObject class
  13. super
  14. end
  15. private
  16. # for better readability
  17. alias remote_attachments resource_collection
  18. # for better readability
  19. def local_attachments
  20. instance.attachments
  21. end
  22. def skip?
  23. ensure_common_ground
  24. attachments_equal?
  25. end
  26. def ensure_common_ground
  27. return if common_ground?
  28. local_attachments.each(&:delete)
  29. end
  30. def common_ground?
  31. return false if remote_attachments.blank?
  32. attachments_equal?
  33. end
  34. def attachments_equal?
  35. remote_attachments.count == local_attachments.count
  36. end
  37. def sequence_name
  38. "Import::Zendesk::Ticket::Comment::#{resource_klass}"
  39. end
  40. def resource_iteration_method
  41. :each
  42. end
  43. end
  44. end
  45. end
  46. end
  47. end
  48. end
  49. end