20191107050249_issue_2460_fix_corrupted_twitter_ids.rb 872 B

1234567891011121314151617181920212223242526
  1. class Issue2460FixCorruptedTwitterIds < ActiveRecord::Migration[5.2]
  2. def up
  3. return if !Setting.find_by(name: 'system_init_done')
  4. Channel.where(area: 'Twitter::Account').each do |channel|
  5. client = nil
  6. begin
  7. client = Twitter::REST::Client.new do |config|
  8. config.consumer_key = channel.options['auth']['consumer_key']
  9. config.consumer_secret = channel.options['auth']['consumer_secret']
  10. config.access_token = channel.options['auth']['oauth_token']
  11. config.access_token_secret = channel.options['auth']['oauth_token_secret']
  12. end
  13. rescue => e
  14. Rails.logger.error "Error while trying to update corrupted Twitter User ID: #{e.message}"
  15. end
  16. next if client.nil?
  17. channel.options['user']['id'] = client.user.id.to_s
  18. channel.save!
  19. end
  20. end
  21. end