2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2013-08-15 22:21:47 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
class Ticket::Number
|
|
|
|
include ApplicationLib
|
2013-08-15 22:21:47 +00:00
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
generate new ticket number
|
|
|
|
|
|
|
|
result = Ticket::Number.generate
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = "1234556" # new ticket number
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
def self.generate
|
2017-10-01 12:25:52 +00:00
|
|
|
49_999.times do
|
2015-04-27 23:19:26 +00:00
|
|
|
number = adapter.generate
|
2019-04-18 03:09:14 +00:00
|
|
|
return number if !Ticket.exists?(number: number)
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2019-04-18 03:09:14 +00:00
|
|
|
|
2021-11-15 15:58:19 +00:00
|
|
|
raise __("Can't generate new ticket number!")
|
2015-04-27 23:19:26 +00:00
|
|
|
end
|
2013-08-15 22:21:47 +00:00
|
|
|
|
|
|
|
=begin
|
|
|
|
|
2019-07-31 08:23:48 +00:00
|
|
|
check if string contains a valid ticket number
|
2013-08-15 22:21:47 +00:00
|
|
|
|
|
|
|
result = Ticket::Number.check('some string [Ticket#123456]')
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = ticket # Ticket model of ticket with matching ticket number
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
def self.check(string)
|
|
|
|
adapter.check(string)
|
|
|
|
end
|
|
|
|
|
2019-04-18 03:09:14 +00:00
|
|
|
# load backend based on config
|
2015-04-27 23:19:26 +00:00
|
|
|
def self.adapter
|
2019-04-18 03:09:14 +00:00
|
|
|
Setting.get('ticket_number')&.constantize ||
|
2021-11-15 15:58:19 +00:00
|
|
|
raise(__('Missing ticket_number setting option'))
|
2013-08-15 22:21:47 +00:00
|
|
|
end
|
|
|
|
end
|