can_touch_references.rb 661 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://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_class = Kernel.const_get(data[:object])
  15. object = object_class.lookup(id: data[:o_id])
  16. return if !object
  17. object.touch # rubocop:disable Rails/SkipsModelValidations
  18. rescue => e
  19. logger.error e
  20. end
  21. end
  22. end