From ef84099db1c4ca6dd53d4440b387c59bf47f21eb Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Fri, 25 May 2018 19:01:53 +0200 Subject: [PATCH] Add rake task for updating username in posts --- lib/tasks/users.rake | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake index 40dce958171..dc0b75ca11e 100644 --- a/lib/tasks/users.rake +++ b/lib/tasks/users.rake @@ -62,6 +62,26 @@ task "users:rename", [:old_username, :new_username] => [:environment] do |_, arg puts "", "User renamed!", "" end +desc "Updates username in quotes and mentions. Use this if the user was renamed before proper renaming existed." +task "users:update_posts", [:old_username, :current_username] => [:environment] do |_, args| + old_username = args[:old_username] + current_username = args[:current_username] + + if !old_username || !current_username + puts "ERROR: Expecting rake posts:update_posts[old_username,current_username]" + exit 1 + end + + user = find_user(current_username) + Jobs::UpdateUsername.new.execute( + user_id: user.id, + old_username: old_username, + new_username: user.username, + avatar_template: user.avatar_template) + + puts "", "Username updated!", "" +end + def find_user(username) user = User.find_by_username(username)