20180809000001_cti_generic_api.rb 2.9 KB

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