2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-10-24 23:46:43 +00:00
|
|
|
class FixedTwitterTicketArticlePreferences7 < ActiveRecord::Migration[5.0]
|
2018-06-28 15:17:27 +00:00
|
|
|
def up
|
|
|
|
|
|
|
|
# return if it's a new setup
|
2020-08-03 08:35:43 +00:00
|
|
|
return if !Setting.exists?(name: 'system_init_done')
|
2018-06-28 15:17:27 +00:00
|
|
|
|
|
|
|
# find article preferences with Twitter::NullObject and replace it with nill to prevent elasticsearch index issue
|
|
|
|
article_type_ids = Ticket::Article::Type.where(name: ['twitter status', 'twitter direct-message']).pluck(:id)
|
|
|
|
article_ids = Ticket::Article.where(type_id: article_type_ids).pluck(:id)
|
|
|
|
article_ids.each do |article_id|
|
|
|
|
article = Ticket::Article.find(article_id)
|
|
|
|
next if !article.preferences
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-06-28 15:17:27 +00:00
|
|
|
changed = false
|
|
|
|
article.preferences.each_value do |value|
|
|
|
|
next if value.class != ActiveSupport::HashWithIndifferentAccess
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-06-28 15:17:27 +00:00
|
|
|
value.each do |sub_key, sub_level|
|
2020-10-22 13:57:01 +00:00
|
|
|
if sub_level.instance_of?(NilClass)
|
2018-06-28 15:17:27 +00:00
|
|
|
value[sub_key] = nil
|
|
|
|
next
|
|
|
|
end
|
2020-10-22 13:57:01 +00:00
|
|
|
if sub_level.instance_of?(Twitter::Place) || sub_level.instance_of?(Twitter::Geo)
|
2018-10-23 03:03:26 +00:00
|
|
|
value[sub_key] = sub_level.to_h
|
2018-06-28 15:17:27 +00:00
|
|
|
changed = true
|
|
|
|
next
|
|
|
|
end
|
|
|
|
next if sub_level.class != Twitter::NullObject
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-06-28 15:17:27 +00:00
|
|
|
value[sub_key] = nil
|
|
|
|
changed = true
|
|
|
|
end
|
|
|
|
end
|
2018-10-23 03:03:26 +00:00
|
|
|
|
|
|
|
if article.preferences[:twitter]&.key?(:geo) && article.preferences[:twitter][:geo].nil?
|
|
|
|
article.preferences[:twitter][:geo] = {}
|
|
|
|
changed = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if article.preferences[:twitter]&.key?(:place) && article.preferences[:twitter][:place].nil?
|
|
|
|
article.preferences[:twitter][:place] = {}
|
|
|
|
changed = true
|
|
|
|
end
|
|
|
|
|
2018-06-28 15:17:27 +00:00
|
|
|
next if !changed
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-06-28 15:17:27 +00:00
|
|
|
article.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|