sub_sequence.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Exchange::FolderContacts::SubSequence < Sequencer::Unit::Base
  3. include ::Sequencer::Unit::Exchange::Folders::Mixin::Folder
  4. include ::Sequencer::Unit::Import::Common::SubSequence::Mixin::ImportJob
  5. uses :ews_folder_ids
  6. def process
  7. return if ews_folder_ids.blank?
  8. ews_folder_ids.each do |folder_id|
  9. folder = ews_folder.find(folder_id)
  10. paginated_item_sequence(folder)
  11. end
  12. end
  13. private
  14. def paginated_item_sequence(folder)
  15. total = folder.total_count
  16. per_page = 1000
  17. pages = (total.to_f / per_page).ceil
  18. display_path = ews_folder.display_path(folder)
  19. (1..pages).each do |page|
  20. offset = (page - 1) * per_page
  21. opts = {
  22. indexed_page_item_view: {
  23. max_entries_returned: per_page,
  24. offset: offset,
  25. base_point: 'Beginning'
  26. }
  27. }
  28. logger.debug { "Fetching and processing #{per_page} items (page: #{page}, offset: #{offset}) from Exchange folder '#{display_path}' (total: #{total})" }
  29. process_folders(folder, display_path, opts)
  30. end
  31. end
  32. def process_folders(folder, display_path, opts)
  33. folder.items(opts).each do |item|
  34. sequence_resource do |parameters|
  35. logger.debug { "Extracting attributes from Exchange item: #{item.get_all_properties!.inspect}" }
  36. parameters.merge(
  37. resource: ::Import::Exchange::ItemAttributes.extract(item),
  38. ews_folder_name: display_path,
  39. )
  40. rescue => e
  41. Rails.logger.error 'Unable to process Exchange folder item'
  42. Rails.logger.debug { item.inspect }
  43. Rails.logger.error e
  44. nil
  45. end
  46. end
  47. end
  48. def sequence
  49. 'Import::Exchange::FolderContact'
  50. end
  51. end