Followup for issue #1394 - Reindex elastic search not possible because of <null>/Twitter::NullObject.
This commit is contained in:
parent
8b554e9d66
commit
5492f4f24f
7 changed files with 34 additions and 54 deletions
|
@ -6,6 +6,7 @@ class Observer::Ticket::Article::CommunicateSms::BackgroundJob
|
|||
def perform
|
||||
article = Ticket::Article.find(@article_id)
|
||||
|
||||
# set retry count
|
||||
article.preferences['delivery_retry'] ||= 0
|
||||
article.preferences['delivery_retry'] += 1
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ class Observer::Ticket::Article::CommunicateTelegram::BackgroundJob
|
|||
article = Ticket::Article.find(@article_id)
|
||||
|
||||
# set retry count
|
||||
record.preferences['delivery_retry'] ||= 0
|
||||
record.preferences['delivery_retry'] += 1
|
||||
article.preferences['delivery_retry'] ||= 0
|
||||
article.preferences['delivery_retry'] += 1
|
||||
|
||||
ticket = Ticket.lookup(id: article.ticket_id)
|
||||
log_error(article, "Can't find ticket.preferences for Ticket.find(#{article.ticket_id})") if !ticket.preferences
|
||||
|
|
|
@ -7,8 +7,8 @@ class Observer::Ticket::Article::CommunicateTwitter::BackgroundJob
|
|||
article = Ticket::Article.find(@article_id)
|
||||
|
||||
# set retry count
|
||||
record.preferences['delivery_retry'] ||= 0
|
||||
record.preferences['delivery_retry'] += 1
|
||||
article.preferences['delivery_retry'] ||= 0
|
||||
article.preferences['delivery_retry'] += 1
|
||||
|
||||
ticket = Ticket.lookup(id: article.ticket_id)
|
||||
log_error(article, "Can't find ticket.preferences for Ticket.find(#{article.ticket_id})") if !ticket.preferences
|
||||
|
@ -62,7 +62,7 @@ class Observer::Ticket::Article::CommunicateTwitter::BackgroundJob
|
|||
mention_ids.push user.id
|
||||
end
|
||||
article.to = to
|
||||
article.preferences['twitter'] = {
|
||||
article.preferences['twitter'] = TweetBase.preferences_cleanup(
|
||||
mention_ids: mention_ids,
|
||||
geo: tweet.geo,
|
||||
retweeted: tweet.retweeted?,
|
||||
|
@ -74,7 +74,7 @@ class Observer::Ticket::Article::CommunicateTwitter::BackgroundJob
|
|||
favorited: tweet.favorited?,
|
||||
truncated: tweet.truncated?,
|
||||
created_at: tweet.created_at,
|
||||
}
|
||||
)
|
||||
end
|
||||
else
|
||||
raise "Unknown tweet type '#{tweet.class}'"
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
class FixedTwitterTicketArticlePreferences4 < 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
|
||||
|
||||
changed = false
|
||||
article.preferences.each_value do |value|
|
||||
next if value.class != ActiveSupport::HashWithIndifferentAccess
|
||||
|
||||
value.each do |sub_key, sub_level|
|
||||
if sub_level.class == NilClass
|
||||
value[sub_key] = nil
|
||||
next
|
||||
end
|
||||
if sub_level.class == Twitter::Place
|
||||
value[sub_key] = sub_level.attrs
|
||||
changed = true
|
||||
next
|
||||
end
|
||||
next if sub_level.class != Twitter::NullObject
|
||||
|
||||
value[sub_key] = nil
|
||||
changed = true
|
||||
end
|
||||
end
|
||||
next if !changed
|
||||
|
||||
article.save!
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
class FixedTwitterTicketArticlePreferences5 < ActiveRecord::Migration[5.0]
|
||||
class FixedTwitterTicketArticlePreferences6 < ActiveRecord::Migration[5.0]
|
||||
def up
|
||||
|
||||
# return if it's a new setup
|
||||
|
@ -21,7 +21,7 @@ class FixedTwitterTicketArticlePreferences5 < ActiveRecord::Migration[5.0]
|
|||
next
|
||||
end
|
||||
if sub_level.class == Twitter::Place || sub_level.class == Twitter::Geo
|
||||
value[sub_key] = sub_level.attrs
|
||||
value[sub_key] = sub_level.to_h
|
||||
changed = true
|
||||
next
|
||||
end
|
||||
|
@ -31,6 +31,17 @@ class FixedTwitterTicketArticlePreferences5 < ActiveRecord::Migration[5.0]
|
|||
changed = true
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
next if !changed
|
||||
|
||||
article.save!
|
|
@ -208,7 +208,7 @@ class TweetBase
|
|||
end
|
||||
|
||||
article_preferences = {
|
||||
twitter: twitter_preferences,
|
||||
twitter: self.class.preferences_cleanup(twitter_preferences),
|
||||
links: [
|
||||
{
|
||||
url: "https://twitter.com/statuses/#{tweet.id}",
|
||||
|
@ -228,7 +228,7 @@ class TweetBase
|
|||
type_id: Ticket::Article::Type.find_by(name: article_type).id,
|
||||
sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
|
||||
internal: false,
|
||||
preferences: preferences_cleanup(article_preferences),
|
||||
preferences: article_preferences,
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -366,7 +366,7 @@ class TweetBase
|
|||
false
|
||||
end
|
||||
|
||||
def preferences_cleanup(preferences)
|
||||
def self.preferences_cleanup(preferences)
|
||||
|
||||
# replace Twitter::NullObject with nill to prevent elasticsearch index issue
|
||||
preferences.each_value do |value|
|
||||
|
@ -378,7 +378,7 @@ class TweetBase
|
|||
next
|
||||
end
|
||||
if sub_level.class == Twitter::Place || sub_level.class == Twitter::Geo
|
||||
value[sub_key] = sub_level.attrs
|
||||
value[sub_key] = sub_level.to_h
|
||||
next
|
||||
end
|
||||
next if sub_level.class != Twitter::NullObject
|
||||
|
@ -386,6 +386,14 @@ class TweetBase
|
|||
value[sub_key] = nil
|
||||
end
|
||||
end
|
||||
|
||||
if preferences[:geo].blank?
|
||||
preferences[:geo] = {}
|
||||
end
|
||||
if preferences[:place].blank?
|
||||
preferences[:place] = {}
|
||||
end
|
||||
|
||||
preferences
|
||||
end
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ class TicketArticleTwitter < ActiveSupport::TestCase
|
|||
from: '@example',
|
||||
body: 'some tweet',
|
||||
internal: false,
|
||||
preferences: TweetBase.new.preferences_cleanup(preferences),
|
||||
preferences: TweetBase.preferences_cleanup(preferences),
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
|
@ -97,7 +97,7 @@ class TicketArticleTwitter < ActiveSupport::TestCase
|
|||
from: '@example',
|
||||
body: 'some tweet',
|
||||
internal: false,
|
||||
preferences: TweetBase.new.preferences_cleanup(preferences),
|
||||
preferences: TweetBase.preferences_cleanup(preferences),
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue