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
|
|
|
|
return if !Setting.find_by(name: 'system_init_done')
|
|
|
|
|
|
|
|
# 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|
|
|
|
|
if sub_level.class == NilClass
|
|
|
|
value[sub_key] = nil
|
|
|
|
next
|
|
|
|
end
|
|
|
|
if sub_level.class == Twitter::Place || sub_level.class == 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
|