Add missing username update in AbstractUserMergeListener
authorMatthias Schmidt <gravatronics@live.com>
Sat, 27 Feb 2016 15:52:46 +0000 (16:52 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 27 Feb 2016 15:52:46 +0000 (16:52 +0100)
wcfsetup/install/files/lib/system/event/listener/AbstractUserMergeListener.class.php

index acefe16e6dc382c5b4a35fcb3cfeb4cb9ddb4cde..4cc383519716f631f8282a8822383e4306d3742e 100644 (file)
@@ -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()));
                }
        }
 }