2014-02-03 19:23:00 +00:00
|
|
|
# Copyright (C) 2012-2014 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
|
2014-02-03 19:23:00 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# generate number
|
2016-06-30 20:04:48 +00:00
|
|
|
49_999.times {
|
2015-04-27 23:19:26 +00:00
|
|
|
number = adapter.generate
|
2015-05-07 10:15:40 +00:00
|
|
|
ticket = Ticket.find_by( number: number )
|
2015-04-27 23:19:26 +00:00
|
|
|
return number if !ticket
|
|
|
|
}
|
2016-03-01 14:26:46 +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
|
|
|
|
|
|
|
|
check if string contrains a valid ticket number
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def self.adapter
|
2015-04-27 21:27:51 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# load backend based on config
|
|
|
|
adapter_name = Setting.get('ticket_number')
|
|
|
|
if !adapter_name
|
2016-03-01 14:26:46 +00:00
|
|
|
raise 'Missing ticket_number setting option'
|
2015-04-27 23:19:26 +00:00
|
|
|
end
|
|
|
|
adapter = load_adapter(adapter_name)
|
|
|
|
if !adapter
|
2016-03-01 14:26:46 +00:00
|
|
|
raise "Can't load ticket_number adapter '#{adapter_name}'"
|
2013-08-15 22:21:47 +00:00
|
|
|
end
|
2015-04-27 23:19:26 +00:00
|
|
|
adapter
|
2013-08-15 22:21:47 +00:00
|
|
|
end
|
|
|
|
end
|