2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2017-05-02 15:21:13 +00:00
|
|
|
module ApplicationModel::CanTouchReferences
|
2017-01-31 17:13:45 +00:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
# methods defined here are going to extend the class, not the instance of it
|
|
|
|
class_methods do
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
touch references by params
|
|
|
|
|
|
|
|
Model.touch_reference_by_params(
|
|
|
|
object: 'Ticket',
|
|
|
|
o_id: 123,
|
|
|
|
)
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def touch_reference_by_params(data)
|
2019-01-06 18:41:29 +00:00
|
|
|
object = data[:object].constantize.lookup(id: data[:o_id])
|
2017-01-31 17:13:45 +00:00
|
|
|
return if !object
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
object.touch # rubocop:disable Rails/SkipsModelValidations
|
2017-01-31 17:13:45 +00:00
|
|
|
rescue => e
|
2017-04-19 10:09:54 +00:00
|
|
|
logger.error e
|
2017-01-31 17:13:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|