can_touch_references.rb 622 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. module ApplicationModel::CanTouchReferences
  3. extend ActiveSupport::Concern
  4. # methods defined here are going to extend the class, not the instance of it
  5. class_methods do
  6. =begin
  7. touch references by params
  8. Model.touch_reference_by_params(
  9. object: 'Ticket',
  10. o_id: 123,
  11. )
  12. =end
  13. def touch_reference_by_params(data)
  14. object = data[:object].constantize.lookup(id: data[:o_id])
  15. return if !object
  16. object.touch # rubocop:disable Rails/SkipsModelValidations
  17. rescue => e
  18. logger.error e
  19. end
  20. end
  21. end