about summary refs log tree commit diff
path: root/db/migrate/20190518150215_reformat_local_statuses.rb
blob: c9433a044267ca70e3de8074c9e3de2bc769aea8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class ReformatLocalStatuses < ActiveRecord::Migration[5.2]
  disable_ddl_transaction!
  def up
    Status.local.without_reblogs.find_each do |status|
      status.content_type = 'text/x-bbcode+markdown'
      text = status.text
      matches = text.match(/\[(right|rfloat)\][\u200c\u200b—–-]+ *(.*?)\[\/\1\]\u200c?\Z/)
      if matches
        status.footer = matches[2].strip
        text = text.sub(/\[(right|rfloat)\][\u200c\u200b—–-]+.*?\[\/\1\]\u200c?\Z/, '').rstrip
      end
      text = text.gsub(/\[(color|colorhex|hexcolor)=\w+\](.*?)\[\/\1\]/, '[b]\2[/b]')
      text = text.gsub(/\[(spin|pulse)\](.*?)\[\/\1\]/, '[b]\2[/b]')
      status.text = text unless text.blank?
      Rails.logger.info("Rewrote status ID #{status.id}")
      status.save
    end
  end
end