Followup improvement for issue#1394 - Reindex elastic search not possible because of <null>/Twitter::NullObject.

This commit is contained in:
Martin Edenhofer 2017-09-08 17:36:42 +02:00
parent 4094bd1d51
commit b96c57210a

View file

@ -1,12 +1,12 @@
class FixedTwitterTicketArticlePreferences4 < ActiveRecord::Migration
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 = Ticket::Article::Type.find_by(name: ['twitter status', 'twitter direct-message'])
article_ids = Ticket::Article.where(type_id: article_type.id).pluck(:id)
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 { |article_id|
article = Ticket::Article.find(article_id)
next if !article.preferences