"Fossies" - the Fresh Open Source Software Archive

Member "db/migrate/20170207081400_ticket_state_priority_defaults.rb" (25 Mar 2021, 1750 Bytes) of package /linux/www/zammad-4.0.0.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "20170207081400_ticket_state_priority_defaults.rb": 3.4.1_vs_3.5.0.

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