merge_history.rb 792 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Ticket::MergeHistory
  3. extend ActiveSupport::Concern
  4. included do
  5. after_destroy :merge_history_cleanup
  6. end
  7. private
  8. def merge_history_cleanup
  9. cleanup_type :received_merge, :id_from, :value_from
  10. cleanup_type :merged_into, :id_to, :value_to
  11. end
  12. def cleanup_type(history_type_name, lookup_attribute_name, target_attribute_name)
  13. type = History.type_lookup history_type_name
  14. object = History.object_lookup self.class.name
  15. History
  16. .where(history_object_id: object, history_type_id: type)
  17. .find_by(lookup_attribute_name => id)
  18. &.update!(target_attribute_name => replacement_title)
  19. end
  20. def replacement_title
  21. "##{number} #{title}"
  22. end
  23. end