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(
|
2020-02-18 16:02:26 -05:00
|
|
|
"cooked LIKE '%class=\"mention-group%' AND raw LIKE :previous_name",
|
2017-01-18 00:39:34 -05: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 02:13:18 -04:00
|
|
|
post.save!(validate: false)
|
2023-01-09 07:20:10 -05:00
|
|
|
end
|
2017-01-18 00:39:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|