From 0f9eda18bec6e2e21e0fba15f90e73f51b2d4572 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 29 Sep 2013 22:57:55 +0200 Subject: [PATCH] Moved to new history api. --- app/models/ticket/escalation.rb | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/app/models/ticket/escalation.rb b/app/models/ticket/escalation.rb index 004bd3392..43f529b43 100644 --- a/app/models/ticket/escalation.rb +++ b/app/models/ticket/escalation.rb @@ -167,7 +167,7 @@ def escalation_calculation_get_sla sla_selected = nil sla_list = Cache.get( 'SLA::List::Active' ) if sla_list == nil - sla_list = Sla.where( :active => true ).all + sla_list = Sla.where( :active => true ) Cache.write( 'SLA::List::Active', sla_list, { :expires_in => 1.hour } ) end sla_list.each {|sla| @@ -221,53 +221,52 @@ def escalation_calculation_get_sla history_list.each { |history_item| # ignore if it isn't a state change - next if !history_item.history_attribute_id - history_attribute = History::Attribute.lookup( :id => history_item.history_attribute_id ); - next if history_attribute.name != 'ticket_state' + next if !history_item['attribute'] + next if history_item['attribute'] != 'ticket_state' # ignore all newer state before start_time - next if history_item.created_at < start_time + next if history_item['created_at'] < start_time # ignore all older state changes after end_time next if last_state_change && last_state_change > end_time # if created_at is later then end_time, use end_time as last time - if history_item.created_at > end_time - history_item.created_at = end_time + if history_item['created_at'] > end_time + history_item['created_at'] = end_time end # get initial state and time if !last_state - last_state = history_item.value_from + last_state = history_item['value_from'] last_state_change = start_time end # check if time need to be counted counted = true - if history_item.value_from == 'pending' + if history_item['value_from'] == 'pending' counted = false - elsif history_item.value_from == 'close' + elsif history_item['value_from'] == 'close' counted = false end - diff = escalation_time_diff( last_state_change, history_item.created_at, sla_selected ) + diff = escalation_time_diff( last_state_change, history_item['created_at'], sla_selected ) if counted - puts "Diff count #{history_item.value_from} -> #{history_item.value_to} / #{last_state_change} -> #{history_item.created_at}" + puts "Diff count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{history_item['created_at']}" total_time_without_pending = total_time_without_pending + diff else - puts "Diff not count #{history_item.value_from} -> #{history_item.value_to} / #{last_state_change} -> #{history_item.created_at}" + puts "Diff not count #{history_item['value_from']} -> #{history_item['value_to']} / #{last_state_change} -> #{history_item['created_at']}" end total_time = total_time + diff - if history_item.value_to == 'pending' + if history_item['value_to'] == 'pending' last_state_is_pending = true else last_state_is_pending = false end # remember for next loop last state - last_state = history_item.value_to - last_state_change = history_item.created_at + last_state = history_item['value_to'] + last_state_change = history_item['created_at'] } # if last state isnt pending, count rest