mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Remap group mentions when group name has been changed.
This commit is contained in:
14
app/services/group_mentions_updater.rb
Normal file
14
app/services/group_mentions_updater.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
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")
|
||||
post.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user