import_stats.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Import
  3. module OTRS
  4. module ImportStats
  5. extend self
  6. def current_state
  7. {
  8. Base: {
  9. done: base_done,
  10. total: base_total,
  11. },
  12. User: {
  13. done: user_done,
  14. total: user_total,
  15. },
  16. Ticket: {
  17. done: ticket_done,
  18. total: ticket_total,
  19. },
  20. }
  21. end
  22. def statistic
  23. # check cache
  24. cache = Rails.cache.read('import_otrs_stats')
  25. return cache if cache
  26. # retrieve statistic
  27. statistic = Import::OTRS::Requester.list
  28. return statistic if !statistic
  29. Rails.cache.write('import_otrs_stats', statistic)
  30. statistic
  31. end
  32. private
  33. def base_done
  34. ::Group.count + ::Ticket::State.count + ::Ticket::Priority.count
  35. end
  36. def base_total
  37. sum_stat(%w[Queue State Priority])
  38. end
  39. def user_done
  40. ::User.count
  41. end
  42. def user_total
  43. sum_stat(%w[User CustomerUser])
  44. end
  45. def ticket_done
  46. ::Ticket.count
  47. end
  48. def ticket_total
  49. sum_stat(%w[Ticket])
  50. end
  51. def sum_stat(objects)
  52. data = statistic
  53. sum = 0
  54. objects.each do |object|
  55. sum += data[object]
  56. end
  57. sum
  58. end
  59. end
  60. end
  61. end