2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-18 13:39:34 +08:00
|
|
|
class GroupMentionsUpdater
|
|
|
|
def self.update(current_name, previous_name)
|
|
|
|
Post
|
|
|
|
.where(
|
2020-02-19 05:02:26 +08:00
|
|
|
"cooked LIKE '%class=\"mention-group%' AND raw LIKE :previous_name",
|
2017-01-18 13:39:34 +08:00
|
|
|
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 14:13:18 +08:00
|
|
|
post.save!(validate: false)
|
2023-01-09 20:20:10 +08:00
|
|
|
end
|
2017-01-18 13:39:34 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|