Followup 6810bc5548 - Fixes #3270 - Ticket selector "within last (relative)" and "within next (relative)" not working correctly.

This commit is contained in:
Rolf Schmidt 2020-12-02 12:20:49 +01:00 committed by Thorsten Eckel
parent 991bfa4f7e
commit e5ddf28be0
2 changed files with 45 additions and 3 deletions

View file

@ -0,0 +1,42 @@
class Issue3270SelectorUpdate < ActiveRecord::Migration[5.2]
def change
# return if it's a new setup
return if !Setting.exists?(name: 'system_init_done')
Overview.find_each do |overview|
fix_selector(overview)
end
Trigger.find_each do |trigger|
fix_selector(trigger)
end
Job.find_each do |job|
fix_selector(job)
end
end
def fix_selector(object)
fixed = false
object.condition.each do |_attribute, attribute_condition|
next if attribute_condition['operator'] != 'within next (relative)' && attribute_condition['operator'] != 'within last (relative)'
attribute_condition['operator'] = if attribute_condition['operator'] == 'within next (relative)'
'before (relative)'
else
'before (after)'
end
fixed = true
end
return if !fixed
save(object)
end
def save(object)
object.save
rescue => e
Rails.logger.error "Migration Issue3270SelectorUpdate failed: #{object.class} - #{object.id} - #{e.inspect}."
end
end

View file

@ -68,7 +68,7 @@ Overview.create_if_not_exists(
pre_condition: 'current_user.id', pre_condition: 'current_user.id',
}, },
'ticket.pending_time' => { 'ticket.pending_time' => {
operator: 'within next (relative)', operator: 'before (relative)',
value: 0, value: 0,
range: 'minute', range: 'minute',
}, },
@ -119,7 +119,7 @@ Overview.create_if_not_exists(
value: Ticket::State.by_category(:pending_reminder).pluck(:id), value: Ticket::State.by_category(:pending_reminder).pluck(:id),
}, },
'ticket.pending_time' => { 'ticket.pending_time' => {
operator: 'within next (relative)', operator: 'before (relative)',
value: 0, value: 0,
range: 'minute', range: 'minute',
}, },
@ -143,7 +143,7 @@ Overview.create_if_not_exists(
role_ids: [overview_role.id], role_ids: [overview_role.id],
condition: { condition: {
'ticket.escalation_at' => { 'ticket.escalation_at' => {
operator: 'within next (relative)', operator: 'before (relative)',
value: '10', value: '10',
range: 'minute', range: 'minute',
}, },