2018-06-28 15:17:27 +00:00
|
|
|
class FixedTwitterTicketArticlePreferences5 < ActiveRecord::Migration[5.0]
|
|
|
|
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
|
|
|
|
value[sub_key] = sub_level.attrs
|
|
|
|
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
|
|
|
|
next if !changed
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-06-28 15:17:27 +00:00
|
|
|
article.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|