From 83f2404b3181ad4ced922c89497c30525d8bfb80 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 7 Jun 2014 11:35:57 +0200 Subject: [PATCH] Added ability to update usernames on user rename --- .../files/lib/data/user/UserAction.class.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/wcfsetup/install/files/lib/data/user/UserAction.class.php b/wcfsetup/install/files/lib/data/user/UserAction.class.php index 4e61f3c91c..735ffe179b 100644 --- a/wcfsetup/install/files/lib/data/user/UserAction.class.php +++ b/wcfsetup/install/files/lib/data/user/UserAction.class.php @@ -14,6 +14,7 @@ use wcf\system\exception\UserInputException; use wcf\system\request\RequestHandler; use wcf\system\WCF; use wcf\util\UserRegistrationUtil; +use wcf\system\event\EventHandler; /** * Executes user-related actions. @@ -327,6 +328,41 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio $userEditor->addToLanguages($languageIDs); } } + + // handle user rename + if (count($this->objects) == 1 && !empty($this->parameters['data']['username'])) { + if ($this->objects[0]->username != $this->parameters['data']['username']) { + $userID = $this->objects[0]->userID; + $username = $this->parameters['data']['username']; + + WCF::getDB()->beginTransaction(); + + // update comments + $sql = "UPDATE wcf".WCF_N."_comment + SET username = ? + WHERE userID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($username, $userID)); + + $sql = "UPDATE wcf".WCF_N."_comment_response + SET username = ? + WHERE userID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($username, $userID)); + + // modification log + $sql = "UPDATE wcf".WCF_N."_modification_log + SET username = ? + WHERE userID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($username, $userID)); + + WCF::getDB()->commitTransaction(); + + // fire event to handle other database tables + EventHandler::getInstance()->fireAction($this, 'rename'); + } + } } /** -- 2.20.1