Moved to separate Ticket::Number class/adapter.

This commit is contained in:
Martin Edenhofer 2013-08-16 00:16:38 +02:00
parent 39cb5c5fa6
commit e4381827ab
6 changed files with 46 additions and 44 deletions

View file

@ -333,7 +333,7 @@ class Channel::EmailParser
UserInfo.current_user_id = user.id
# get ticket# from subject
ticket = Ticket.number_check( mail[:subject] )
ticket = Ticket::Number.check( mail[:subject] )
# set ticket state to open if not new
if ticket

View file

@ -4,7 +4,7 @@ require 'time_calculation'
require 'sla'
class Ticket < ApplicationModel
before_create :number_generate, :check_defaults
before_create :check_generate, :check_defaults
before_update :check_defaults
before_destroy :destroy_dependencies
after_create :notify_clients_after_create
@ -24,10 +24,6 @@ class Ticket < ApplicationModel
attr_accessor :callback_loop
def self.number_check (string)
self.number_adapter.number_check_item(string)
end
def agent_of_group
Group.find( self.group_id ).users.where( :active => true ).joins(:roles).where( 'roles.name' => 'Agent', 'roles.active' => true ).uniq()
end
@ -504,21 +500,6 @@ class Ticket < ApplicationModel
return bind
end
def self.number_adapter
# load backend based on config
adapter_name = Setting.get('ticket_number')
adapter = nil
case adapter_name
when Symbol, String
require "ticket/number/#{adapter_name.to_s.downcase}"
adapter = Ticket::Number.const_get("#{adapter_name.to_s.capitalize}")
else
raise "Missing number_adapter '#{adapter_name}'"
end
return adapter
end
def self.escalation_calculation_rebuild
ticket_state_list_open = Ticket::State.by_category( 'open' )
@ -731,21 +712,11 @@ returns
private
def number_generate
def check_generate
return if self.number
# generate number
(1..25_000).each do |i|
number = Ticket.number_adapter.number_generate_item()
ticket = Ticket.where( :number => number ).first
if ticket != nil
number = Ticket.number_adapter.number_generate_item()
else
self.number = number
return number
end
end
self.number = Ticket::Number.generate
end
def check_defaults
if !self.owner_id
self.owner_id = 1
@ -874,7 +845,4 @@ returns
diff
end
class Number
end
end

View file

@ -3,7 +3,7 @@
module Ticket::Number::Date
extend self
def number_generate_item
def generate
# get config
config = Setting.get('ticket_number_date')
@ -64,7 +64,7 @@ module Ticket::Number::Date
end
return number
end
def number_check_item (string)
def check(string)
# get config
system_id = Setting.get('system_id') || ''

View file

@ -3,7 +3,7 @@
module Ticket::Number::Increment
extend self
def number_generate_item
def generate
# get config
config = Setting.get('ticket_number_increment')
@ -68,7 +68,7 @@ module Ticket::Number::Increment
return number
end
def number_check_item (string)
def check(string)
# get config
system_id = Setting.get('system_id') || ''

View file

@ -0,0 +1,34 @@
class UpdateTicketNumber < ActiveRecord::Migration
def up
Setting.create_or_update(
:title => 'Ticket Number Format',
:name => 'ticket_number',
:area => 'Ticket::Number',
:description => 'Selects the ticket number generator module. "Increment" increments the ticket
number, the SystemID and the counter are used with SystemID.Counter format (e.g. 1010138, 1010139).
With "Date" the ticket numbers will be generated by the current date, the SystemID and the counter.
The format looks like Year.Month.Day.SystemID.counter (e.g. 201206231010138, 201206231010139).
With param "Checksum => true" the counter will be appended as checksum to the string. The format
looks like SystemID.Counter.CheckSum (e. g. 10101384, 10101392) or Year.Month.Day.SystemID.Counter.CheckSum (e.g. 2012070110101520, 2012070110101535).',
:options => {
:form => [
{
:display => '',
:null => true,
:name => 'ticket_number',
:tag => 'select',
:options => {
'Ticket::Number::Increment' => 'Increment (SystemID.Counter)',
'Ticket::Number::Date' => 'Date (Year.Month.Day.SystemID.Counter)',
},
},
],
},
:state => 'Ticket::Number::Increment',
:frontend => false
)
end
def down
end
end

View file

@ -712,13 +712,13 @@ Setting.create_if_not_exists(
:name => 'ticket_number',
:tag => 'select',
:options => {
'increment' => 'Increment (SystemID.Counter)',
'date' => 'Date (Year.Month.Day.SystemID.Counter)',
'Ticket::Number::Increment' => 'Increment (SystemID.Counter)',
'Ticket::Number::Date' => 'Date (Year.Month.Day.SystemID.Counter)',
},
},
],
},
:state => 'increment',
:state => 'Ticket::Number::Increment',
:frontend => false
)
Setting.create_if_not_exists(