20180809000001_cti_generic_api.rb 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. class CtiGenericApi < ActiveRecord::Migration[5.1]
  2. def up
  3. # return if it's a new setup
  4. return if !Setting.exists?(name: 'system_init_done')
  5. Setting.create_if_not_exists(
  6. title: 'cti integration',
  7. name: 'cti_integration',
  8. area: 'Integration::Switch',
  9. description: 'Defines if generic CTI is enabled or not.',
  10. options: {
  11. form: [
  12. {
  13. display: '',
  14. null: true,
  15. name: 'cti_integration',
  16. tag: 'boolean',
  17. options: {
  18. true => 'yes',
  19. false => 'no',
  20. },
  21. },
  22. ],
  23. },
  24. state: false,
  25. preferences: {
  26. prio: 1,
  27. trigger: ['menu:render', 'cti:reload'],
  28. authentication: true,
  29. permission: ['admin.integration'],
  30. },
  31. frontend: true
  32. )
  33. Setting.create_if_not_exists(
  34. title: 'cti config',
  35. name: 'cti_config',
  36. area: 'Integration::Cti',
  37. description: 'Defines the cti config.',
  38. options: {},
  39. state: { 'outbound' => { 'routing_table' => [], 'default_caller_id' => '' }, 'inbound' => { 'block_caller_ids' => [] } },
  40. preferences: {
  41. prio: 2,
  42. permission: ['admin.integration'],
  43. },
  44. frontend: false,
  45. )
  46. Setting.create_if_not_exists(
  47. title: 'CTI Token',
  48. name: 'cti_token',
  49. area: 'Integration::Cti',
  50. description: 'Token for cti.',
  51. options: {
  52. form: [
  53. {
  54. display: '',
  55. null: false,
  56. name: 'cti_token',
  57. tag: 'input',
  58. },
  59. ],
  60. },
  61. state: SecureRandom.urlsafe_base64(20),
  62. preferences: {
  63. permission: ['admin.integration'],
  64. },
  65. frontend: false
  66. )
  67. add_column :cti_logs, :queue, :string, limit: 250, null: true if !column_exists?(:cti_logs, :queue)
  68. add_column :cti_logs, :initialized_at, :string, limit: 250, null: true if !column_exists?(:cti_logs, :initialized_at)
  69. add_column :cti_logs, :duration_waiting_time, :integer, null: true if !column_exists?(:cti_logs, :duration_waiting_time)
  70. add_column :cti_logs, :duration_talking_time, :integer, null: true if !column_exists?(:cti_logs, :duration_talking_time)
  71. # fixes issue #2183 - Mysql2::Error: Invalid default value for 'start_at'
  72. if ActiveRecord::Base.connection_config[:adapter] == 'mysql2'
  73. # disable the MySQL strict_mode for the current connection
  74. execute("SET sql_mode = ''")
  75. change_column_default :cti_logs, :start, '0000-00-00 00:00:00'
  76. change_column_default :cti_logs, :end, '0000-00-00 00:00:00'
  77. end
  78. rename_column :cti_logs, :start, :start_at
  79. rename_column :cti_logs, :end, :end_at
  80. end
  81. end