attachments.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 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. @local_attachments ||= instance.attachments&.filter { |attachment| attachment.preferences&.dig('Content-Disposition') != 'inline' }
  15. end
  16. def skip?
  17. ensure_common_ground
  18. attachments_equal?
  19. end
  20. def ensure_common_ground
  21. return if attachments_equal?
  22. local_attachments.each(&:delete)
  23. end
  24. def attachments_equal?
  25. remote_attachments.count == local_attachments.count
  26. end
  27. def sequence_name
  28. "Import::Zendesk::Ticket::Comment::#{resource_klass}"
  29. end
  30. def resource_iteration_method
  31. :each
  32. end
  33. end