statistics_diff.rb 911 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Ldap::Sources::Lost::StatisticsDiff < Sequencer::Unit::Base
  3. include ::Sequencer::Unit::Import::Common::Model::Statistics::Mixin::EmptyDiff
  4. uses :lost_ids
  5. def process
  6. # deactivated count is tracked as a separate number
  7. # since they don't have to be in the sum (e.g. deleted in LDAP)
  8. state.provide(:statistics_diff) do
  9. diff.merge(
  10. role_ids: role_ids,
  11. deactivated: lost_ids.size
  12. )
  13. end
  14. end
  15. def role_ids
  16. lost_ids.each_with_object({}) do |user_id, result|
  17. role_ids = ::User.joins(:roles)
  18. .where(id: user_id)
  19. .pluck(:'roles_users.role_id')
  20. role_ids.each do |role_id|
  21. result[role_id] ||= diff
  22. result[role_id][:deactivated] += 1
  23. end
  24. end
  25. end
  26. end