2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2017-09-08 08:28:34 +00:00
|
|
|
# Rails dropped the class
|
|
|
|
# ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlDateTime
|
|
|
|
# via: https://github.com/rails/rails/commit/f1a0fa9e19b7e4ccaea191fc6cf0613880222ee7
|
2017-09-26 12:00:34 +00:00
|
|
|
# ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer
|
|
|
|
# via: https://github.com/rails/rails/commit/aafee233fb3b4211ee0bfb1fca776c159bd1067e
|
2017-09-08 08:28:34 +00:00
|
|
|
# which we use in stored Cti::Log instance preferences.
|
|
|
|
# Since we don't need the instances but just an Hash we have to:
|
|
|
|
# - create a dummy class
|
|
|
|
# - loop over all instances
|
|
|
|
# - deserialize them in the preferences
|
|
|
|
# - replace them in the preferences with the Hash version
|
|
|
|
|
|
|
|
# create a dummy class
|
|
|
|
module ActiveRecord
|
|
|
|
module ConnectionAdapters
|
|
|
|
class AbstractMysqlAdapter
|
|
|
|
class MysqlDateTime < Type::DateTime
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-11-24 16:20:57 +00:00
|
|
|
|
2017-09-26 12:00:34 +00:00
|
|
|
module ActiveRecord
|
|
|
|
module ConnectionAdapters
|
|
|
|
module PostgreSQL
|
|
|
|
module OID
|
|
|
|
class Integer < Type::Integer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-09-08 08:28:34 +00:00
|
|
|
|
|
|
|
class CtiLogPreferencesMigration < ActiveRecord::Migration[5.0]
|
|
|
|
|
|
|
|
def change
|
2017-09-26 12:22:38 +00:00
|
|
|
|
2017-09-08 08:28:34 +00:00
|
|
|
# correct all entries
|
2020-09-30 09:07:01 +00:00
|
|
|
directions = %w[from to]
|
2017-09-26 12:00:34 +00:00
|
|
|
Cti::Log.all.pluck(:id).each do |item_id|
|
|
|
|
item = Cti::Log.find(item_id)
|
2017-09-08 08:28:34 +00:00
|
|
|
next if !item.preferences
|
|
|
|
next if item.preferences.blank?
|
|
|
|
|
|
|
|
# check from and to keys which hold the instances
|
2017-09-26 12:22:38 +00:00
|
|
|
preferences = {}
|
2020-09-30 09:07:01 +00:00
|
|
|
directions.each do |direction|
|
2017-09-08 08:28:34 +00:00
|
|
|
next if item.preferences[direction].blank?
|
|
|
|
|
|
|
|
# loop over all instances and covert them
|
|
|
|
# to an Hash via .attributes
|
|
|
|
updated = item.preferences[direction].each_with_object([]) do |caller_id, new_direction|
|
2017-09-08 15:39:57 +00:00
|
|
|
next if !caller_id.respond_to?(:attributes)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-09-08 08:28:34 +00:00
|
|
|
new_direction.push(caller_id.attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
# overwrite the old key with the converted data
|
2017-09-26 12:22:38 +00:00
|
|
|
preferences[direction] = updated
|
2017-09-08 08:28:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# update entry
|
2017-11-23 08:09:44 +00:00
|
|
|
item.update_column(:preferences, preferences) # rubocop:disable Rails/SkipsModelValidations
|
2017-09-08 08:28:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|