http_log.rb 669 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class HttpLog < ApplicationModel
  3. store :request
  4. store :response
  5. # See https://github.com/zammad/zammad/issues/2100
  6. before_save :messages_to_utf8
  7. =begin
  8. cleanup old http logs
  9. HttpLog.cleanup
  10. optional you can put the max oldest chat entries as argument
  11. HttpLog.cleanup(1.month)
  12. =end
  13. def self.cleanup(diff = 1.month)
  14. HttpLog.where('created_at < ?', Time.zone.now - diff).delete_all
  15. true
  16. end
  17. private
  18. def messages_to_utf8
  19. request.transform_values! { |v| v.try(:utf8_encode) || v }
  20. response.transform_values! { |v| v.try(:utf8_encode) || v }
  21. end
  22. end