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