attachments.rb 1.0 KB

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