From e5ddf28be01a1c26aae8ac06ebc42ab042067122 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Wed, 2 Dec 2020 12:20:49 +0100 Subject: [PATCH] Followup 6810bc55480cbede477250372e71ded4aa4a125b - Fixes #3270 - Ticket selector "within last (relative)" and "within next (relative)" not working correctly. --- ...0201202080338_issue3270_selector_update.rb | 42 +++++++++++++++++++ db/seeds/overviews.rb | 6 +-- 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20201202080338_issue3270_selector_update.rb diff --git a/db/migrate/20201202080338_issue3270_selector_update.rb b/db/migrate/20201202080338_issue3270_selector_update.rb new file mode 100644 index 000000000..766998836 --- /dev/null +++ b/db/migrate/20201202080338_issue3270_selector_update.rb @@ -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 diff --git a/db/seeds/overviews.rb b/db/seeds/overviews.rb index f67c69f2d..71630793a 100644 --- a/db/seeds/overviews.rb +++ b/db/seeds/overviews.rb @@ -68,7 +68,7 @@ Overview.create_if_not_exists( pre_condition: 'current_user.id', }, 'ticket.pending_time' => { - operator: 'within next (relative)', + operator: 'before (relative)', value: 0, range: 'minute', }, @@ -119,7 +119,7 @@ Overview.create_if_not_exists( value: Ticket::State.by_category(:pending_reminder).pluck(:id), }, 'ticket.pending_time' => { - operator: 'within next (relative)', + operator: 'before (relative)', value: 0, range: 'minute', }, @@ -143,7 +143,7 @@ Overview.create_if_not_exists( role_ids: [overview_role.id], condition: { 'ticket.escalation_at' => { - operator: 'within next (relative)', + operator: 'before (relative)', value: '10', range: 'minute', },