Find article preferences with Twitter::NullObject and replace it with nill to prevent elasticsearch index issue.

This commit is contained in:
Martin Edenhofer 2017-03-14 06:21:35 +01:00
parent ee0677e31c
commit 9c72ff18f9
2 changed files with 39 additions and 1 deletions

View file

@ -0,0 +1,25 @@
class FixedTwitterTicketArticlePreferences < ActiveRecord::Migration
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 = Ticket::Article::Type.find_by(name: 'twitter status')
Ticket::Article.where(type_id: article_type.id).each { |article|
next if !article.preferences
changed = false
article.preferences.each { |_key, value|
next if value.class != ActiveSupport::HashWithIndifferentAccess
value.each { |sub_key, sub_level|
next if sub_level.class != Twitter::NullObject
value[sub_key] = nil
changed = true
}
}
next if !changed
article.save!
}
end
end

View file

@ -219,7 +219,7 @@ class TweetBase
sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
internal: false,
preferences: {
twitter: preferences,
twitter: preferences_cleanup(preferences),
links: [
{
url: "https://twitter.com/statuses/#{tweet.id}",
@ -373,4 +373,17 @@ class TweetBase
false
end
def preferences_cleanup(preferences)
# replace Twitter::NullObject with nill to prevent elasticsearch index issue
preferences.each { |_key, value|
next if value.class != ActiveSupport::HashWithIndifferentAccess
value.each { |sub_key, sub_level|
next if sub_level.class != Twitter::NullObject
value[sub_key] = nil
}
}
preferences
end
end