Added username to wcf1_conversation_to_user
authorAlexander Ebert <ebert@woltlab.com>
Mon, 8 Jul 2013 11:18:20 +0000 (13:18 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 8 Jul 2013 11:18:20 +0000 (13:18 +0200)
files/lib/data/conversation/ConversationEditor.class.php
install.sql

index 4f96ad1b2c8b7e631edfa40823d0717bf5fb5a2a..a7e3da7b9269bf7fda48845e05096bf5215b38b3 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace wcf\data\conversation;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
+
 use wcf\data\conversation\message\ConversationMessage;
 use wcf\data\DatabaseObjectEditor;
 use wcf\system\WCF;
@@ -55,17 +57,37 @@ class ConversationEditor extends DatabaseObjectEditor {
         * @param       array<integer>  $invisibleParticipantIDs
         */
        public function updateParticipants(array $participantIDs, array $invisibleParticipantIDs = array()) {
+               $usernames = array();
+               if (!empty($participantIDs) || !empty($invisibleParticipantIDs)) {
+                       $conditions = new PreparedStatementConditionBuilder();
+                       $conditions->add("userID IN (?)", array(array_merge($participantIDs, $invisibleParticipantIDs)));
+                       
+                       $sql = "SELECT  userID, username
+                               FROM    wcf".WCF_N."_user
+                               ".$conditions;
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute($conditions->getParameters());
+                       while ($row = $statement->fetchArray()) {
+                               $usernames[$row['userID']] = $row['username'];
+                       }
+               }
+               
                if (!empty($participantIDs)) {
                        WCF::getDB()->beginTransaction();
                        $sql = "INSERT INTO             wcf".WCF_N."_conversation_to_user
-                                                       (conversationID, participantID, isInvisible)
-                               VALUES                  (?, ?, ?)
+                                                       (conversationID, participantID, username, isInvisible)
+                               VALUES                  (?, ?, ?, ?)
                                ON DUPLICATE KEY
                                UPDATE                  hideConversation = 0";
                        $statement = WCF::getDB()->prepareStatement($sql);
                        
                        foreach ($participantIDs as $userID) {
-                               $statement->execute(array($this->conversationID, $userID, 0));
+                               $statement->execute(array(
+                                       $this->conversationID,
+                                       $userID,
+                                       $usernames[$userID],
+                                       0
+                               ));
                        }
                        WCF::getDB()->commitTransaction();
                }
@@ -73,12 +95,17 @@ class ConversationEditor extends DatabaseObjectEditor {
                if (!empty($invisibleParticipantIDs)) {
                        WCF::getDB()->beginTransaction();
                        $sql = "INSERT INTO             wcf".WCF_N."_conversation_to_user
-                                                       (conversationID, participantID, isInvisible)
-                               VALUES                  (?, ?, ?)";
+                                                       (conversationID, participantID, username, isInvisible)
+                               VALUES                  (?, ?, ?, ?)";
                        $statement = WCF::getDB()->prepareStatement($sql);
                        
                        foreach ($invisibleParticipantIDs as $userID) {
-                               $statement->execute(array($this->conversationID, $userID, 1));
+                               $statement->execute(array(
+                                       $this->conversationID,
+                                       $userID,
+                                       $usernames[$userID],
+                                       1
+                               ));
                        }
                        WCF::getDB()->commitTransaction();
                }
@@ -114,14 +141,12 @@ class ConversationEditor extends DatabaseObjectEditor {
         */
        public function updateParticipantSummary() {
                $users = array();
-               $sql = "SELECT          conversation_to_user.participantID AS userID, conversation_to_user.hideConversation, user_table.username
-                       FROM            wcf".WCF_N."_conversation_to_user conversation_to_user
-                       LEFT JOIN       wcf".WCF_N."_user user_table
-                       ON              (user_table.userID = conversation_to_user.participantID)
-                       WHERE           conversation_to_user.conversationID = ?
-                                       AND conversation_to_user.participantID <> ?
-                                       AND conversation_to_user.isInvisible = 0
-                       ORDER BY        user_table.username";
+               $sql = "SELECT          participantID AS userID, hideConversation, username
+                       FROM            wcf".WCF_N."_conversation_to_user
+                       WHERE           conversationID = ?
+                                       participantID <> ?
+                                       isInvisible = 0
+                       ORDER BY        username";
                $statement = WCF::getDB()->prepareStatement($sql, 5);
                $statement->execute(array($this->conversationID, $this->userID));
                while ($row = $statement->fetchArray()) {
index 163265cde0a0e9cdc72959f01e2edc9e693dc1f1..eadb1a25d9df798892dde2eae358ce93fc779d00 100644 (file)
@@ -25,6 +25,7 @@ DROP TABLE IF EXISTS wcf1_conversation_to_user;
 CREATE TABLE wcf1_conversation_to_user (
        conversationID INT(10) NOT NULL,
        participantID INT(10),
+       username VARCHAR(255) NOT NULL DEFAULT '',
        hideConversation TINYINT(1) NOT NULL DEFAULT 0,
        isInvisible TINYINT(1) NOT NULL DEFAULT 0,
        lastVisitTime INT(10) NOT NULL DEFAULT 0,