20170207081400_ticket_state_priority_defaults.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class TicketStatePriorityDefaults < ActiveRecord::Migration[4.2]
  3. def up
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. add_column :ticket_states, :default_create, :boolean, null: false, default: false
  7. add_index :ticket_states, :default_create
  8. add_column :ticket_states, :default_follow_up, :boolean, null: false, default: false
  9. add_index :ticket_states, :default_follow_up
  10. add_column :ticket_priorities, :default_create, :boolean, null: false, default: false
  11. add_index :ticket_priorities, :default_create
  12. # Set defaults
  13. ticket_state_new = Ticket::State.find_by(name: 'new')
  14. if !ticket_state_new
  15. ticket_state_new = Ticket::State.first
  16. end
  17. if ticket_state_new
  18. ticket_state_new.default_create = true
  19. ticket_state_new.save!
  20. end
  21. ticket_state_open = Ticket::State.find_by(name: 'open')
  22. if !ticket_state_open
  23. ticket_state_open = Ticket::State.first
  24. end
  25. if ticket_state_open
  26. ticket_state_open.default_follow_up = true
  27. ticket_state_open.save!
  28. end
  29. ticket_priority = Ticket::Priority.find_by(name: '2 normal')
  30. if !ticket_priority
  31. ticket_priority = Ticket::Priority.first
  32. end
  33. if ticket_priority
  34. ticket_priority.default_create = true
  35. ticket_priority.save!
  36. end
  37. Rails.cache.clear
  38. end
  39. def down
  40. remove_index :ticket_states, :default_create
  41. remove_column :ticket_states, :default_create, :boolean
  42. remove_index :ticket_states, :default_follow_up
  43. remove_column :ticket_states, :default_follow_up, :boolean
  44. remove_index :ticket_priorities, :default_create
  45. remove_column :ticket_priorities, :default_create, :boolean
  46. Rails.cache.clear
  47. end
  48. end