touches_associations.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # Update assigned customer and organization change_time information on ticket changes.
  3. module Ticket::TouchesAssociations
  4. extend ActiveSupport::Concern
  5. included do
  6. after_create :ticket_touch_associations
  7. after_update :ticket_touch_associations
  8. after_destroy :ticket_touch_associations
  9. end
  10. private
  11. def ticket_touch_associations
  12. # return if we run import mode
  13. return true if Setting.get('import_mode')
  14. touch_customer
  15. touch_organization
  16. end
  17. def touch_customer
  18. return if saved_changes['customer_id'].blank?
  19. return if saved_changes['customer_id'][0] == saved_changes['customer_id'][1]
  20. # touch old customer
  21. User.lookup(id: saved_changes['customer_id'][0])&.touch # rubocop:disable Rails/SkipsModelValidations
  22. # touch new/current customer
  23. customer&.touch # rubocop:disable Rails/SkipsModelValidations
  24. end
  25. def touch_organization
  26. return if saved_changes['organization_id'].blank?
  27. return if saved_changes['organization_id'][0] == saved_changes['organization_id'][1]
  28. # touch old organization
  29. Organization.lookup(id: saved_changes['organization_id'][0])&.touch # rubocop:disable Rails/SkipsModelValidations
  30. # touch new organization
  31. organization&.touch # rubocop:disable Rails/SkipsModelValidations
  32. end
  33. end