20230720123018_ticket_time_accounting_check.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class TicketTimeAccountingCheck < ActiveRecord::Migration[6.1]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. add_workflow
  7. update_time_accounting_selector
  8. end
  9. def add_workflow
  10. CoreWorkflow.create_if_not_exists(
  11. name: 'base - ticket time accouting check',
  12. object: 'Ticket',
  13. condition_saved: {
  14. 'custom.module': {
  15. operator: 'match all modules',
  16. value: [
  17. 'CoreWorkflow::Custom::TicketTimeAccountingCheck',
  18. ],
  19. },
  20. },
  21. perform: {
  22. 'custom.module': {
  23. execute: ['CoreWorkflow::Custom::TicketTimeAccountingCheck']
  24. },
  25. },
  26. changeable: false,
  27. priority: 99_999,
  28. created_by_id: 1,
  29. updated_by_id: 1,
  30. )
  31. end
  32. def update_time_accounting_selector # rubocop:disable Metrics/AbcSize
  33. selector = Setting.get('time_accounting_selector')
  34. return if selector.blank?
  35. return if selector[:condition].blank?
  36. selector[:condition].each do |_key, value|
  37. if value[:pre_condition] == 'not_set'
  38. value[:operator] = 'not set'
  39. value.delete(:pre_condition)
  40. value.delete(:value)
  41. value.delete(:value_completion)
  42. end
  43. if value[:operator] == 'contains'
  44. value[:operator] = 'regex match'
  45. end
  46. if value[:operator] == 'contains not'
  47. value[:operator] = 'regex mismatch'
  48. end
  49. end
  50. Setting.set('time_accounting_selector', selector)
  51. end
  52. end