20170207081400_ticket_state_priority_defaults.rb 1.7 KB

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