From: Matthias Schmidt Date: Sat, 27 Feb 2016 15:52:46 +0000 (+0100) Subject: Add missing username update in AbstractUserMergeListener X-Git-Tag: 3.0.0_Beta_1~2046 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f5be04ca68d36595e5acb6c638be06cf7d80905b;p=GitHub%2FWoltLab%2FWCF.git Add missing username update in AbstractUserMergeListener --- diff --git a/wcfsetup/install/files/lib/system/event/listener/AbstractUserMergeListener.class.php b/wcfsetup/install/files/lib/system/event/listener/AbstractUserMergeListener.class.php index acefe16e6d..4cc3835197 100644 --- a/wcfsetup/install/files/lib/system/event/listener/AbstractUserMergeListener.class.php +++ b/wcfsetup/install/files/lib/system/event/listener/AbstractUserMergeListener.class.php @@ -18,10 +18,12 @@ abstract class AbstractUserMergeListener implements IParameterizedEventListener /** * data of the updated database tables * can either contain the database table as value if `userID` is the name - * of the database column and no ignore is needed or an array with values - * `name` (database table name), `userID`(name of the database table column - * containing the id of the user) and `ignore` (optional) if an UPDATE IGNORE - * query should be used. + * of the database column and neither username update nor ignore is needed + * or an array with values `name` (database table name), `userID` (name of + * the database table column containing the id of the user), `username` + * (optional; database column name for the username if it also needs to be + * updated, default value: username) and `ignore` (optional if an UPDATEI + * GNORE query should be used) * `{WCF_N}` will be automatically replaced with the number of the WCF installation * (only with PHP 5.6 string concatenation is possible in property declarations) * @var array @@ -37,15 +39,22 @@ abstract class AbstractUserMergeListener implements IParameterizedEventListener $databaseTable = ['name' => $databaseTable]; } if (!isset($databaseTable['userID'])) $databaseTable['userID'] = 'userID'; + if (!array_key_exists('username', $databaseTable)) $databaseTable['username'] = 'username'; $conditionBuilder = new PreparedStatementConditionBuilder(); $conditionBuilder->add($databaseTable['userID']." IN (?)", [$eventObj->mergedUserIDs]); + $parameters = [$eventObj->destinationUserID]; + if (!empty($databaseTable['username'])) { + $parameters[] = $eventObj->users[$eventObj->destinationUserID]->username; + } + $sql = "UPDATE".(!empty($databaseTable['ignore']) ? " IGNORE" : "")." ".str_replace('{WCF_N}', WCF_N, $databaseTable['name'])." SET ".$databaseTable['userID']." = ? - ".$conditionBuilder; + ".(!empty($databaseTable['username']) ? ", ".$databaseTable['username']." = ? " : "") + .$conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array_merge([$eventObj->destinationUserID], $conditionBuilder->getParameters())); + $statement->execute(array_merge($parameters, $conditionBuilder->getParameters())); } } }