2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-18 00:39:34 -05:00
|
|
|
class GroupMentionsUpdater
|
|
|
|
def self.update(current_name, previous_name)
|
|
|
|
Post.where(
|
|
|
|
"cooked LIKE '%class=\"mention-group\"%' AND raw LIKE :previous_name",
|
|
|
|
previous_name: "%@#{previous_name}%"
|
|
|
|
).find_in_batches do |posts|
|
|
|
|
|
|
|
|
posts.each do |post|
|
|
|
|
post.raw.gsub!(/(^|\s)(@#{previous_name})(\s|$)/, "\\1@#{current_name}\\3")
|
2017-04-04 02:13:18 -04:00
|
|
|
post.save!(validate: false)
|
2017-01-18 00:39:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|