number.rb 901 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Ticket::Number
  3. include ApplicationLib
  4. =begin
  5. generate new ticket number
  6. result = Ticket::Number.generate
  7. returns
  8. result = "1234556" # new ticket number
  9. =end
  10. def self.generate
  11. 49_999.times do
  12. number = adapter.generate
  13. return number if !Ticket.exists?(number: number)
  14. end
  15. raise __('The new ticket number could not be generated.')
  16. end
  17. =begin
  18. check if string contains a valid ticket number
  19. result = Ticket::Number.check('some string [Ticket#123456]')
  20. returns
  21. result = ticket # Ticket model of ticket with matching ticket number
  22. =end
  23. def self.check(string)
  24. adapter.check(string)
  25. end
  26. # load backend based on config
  27. def self.adapter
  28. Setting.get('ticket_number')&.constantize ||
  29. raise(__("The setting 'ticket_number' was not configured."))
  30. end
  31. end