20201202080338_issue3270_selector_update.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Issue3270SelectorUpdate < ActiveRecord::Migration[5.2]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. Overview.find_each do |overview|
  7. fix_selector(overview)
  8. end
  9. Trigger.find_each do |trigger|
  10. fix_selector(trigger)
  11. end
  12. Job.find_each do |job|
  13. fix_selector(job)
  14. end
  15. end
  16. def fix_selector(object)
  17. fixed = false
  18. object.condition.each_value do |attribute_condition|
  19. next if attribute_condition['operator'] != 'within next (relative)' && attribute_condition['operator'] != 'within last (relative)'
  20. attribute_condition['operator'] = if attribute_condition['operator'] == 'within next (relative)'
  21. 'till (relative)'
  22. else
  23. 'from (relative)'
  24. end
  25. fixed = true
  26. end
  27. return if !fixed
  28. save(object)
  29. end
  30. def save(object)
  31. object.save
  32. rescue => e
  33. Rails.logger.error "Migration Issue3270SelectorUpdate failed: #{object.class} - #{object.id} - #{e.inspect}."
  34. end
  35. end