http_log.rb 654 B

1234567891011121314151617181920212223242526272829303132333435
  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. where(created_at: ...diff.ago)
  15. .delete_all
  16. true
  17. end
  18. private
  19. def messages_to_utf8
  20. request.transform_values! { |v| v.try(:utf8_encode) || v }
  21. response.transform_values! { |v| v.try(:utf8_encode) || v }
  22. end
  23. end