2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-01-08 15:29:34 +00:00
|
|
|
class Sequencer
|
|
|
|
class Unit
|
|
|
|
module Import
|
|
|
|
module Zendesk
|
|
|
|
class ObjectsTotalCount < Sequencer::Unit::Common::Provider::Attribute
|
|
|
|
include ::Sequencer::Unit::Import::Common::Model::Statistics::Mixin::EmptyDiff
|
|
|
|
|
|
|
|
uses :client
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def statistics_diff
|
2021-06-23 11:35:27 +00:00
|
|
|
%i[Groups Users Organizations Tickets].index_with do |object|
|
|
|
|
empty_diff.merge(
|
2021-01-21 07:22:17 +00:00
|
|
|
total: request(object).count!
|
|
|
|
)
|
2018-01-08 15:29:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-21 07:22:17 +00:00
|
|
|
# the special "incremental_export" logic is needed because Zendesk
|
|
|
|
# archives records and doesn't return them via e.g. client.tickets
|
|
|
|
# endpoint as described here:
|
|
|
|
# https://github.com/zammad/zammad/issues/558#issuecomment-267951351
|
|
|
|
# Counting via the incremental_export endpoint has the limitations
|
|
|
|
# that it returns max. 1000. That's why we need to update the total
|
|
|
|
# number while importing in the resource loop
|
|
|
|
def request(object)
|
|
|
|
resource_class = "::ZendeskAPI::#{object.to_s.singularize}".safe_constantize
|
|
|
|
if resource_class.respond_to?(:incremental_export)
|
|
|
|
# read as: ::ZendeskAPI::Ticket.incremental_export(client, 1)
|
|
|
|
resource_class.incremental_export(client, 1)
|
|
|
|
else
|
|
|
|
# read as: client.groups
|
|
|
|
client.send(object.to_s.underscore.to_sym)
|
|
|
|
end
|
2018-01-08 15:29:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|