Use new event listeners for user merge/rename
authorMatthias Schmidt <gravatronics@live.com>
Sat, 27 Feb 2016 14:31:00 +0000 (15:31 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 27 Feb 2016 14:31:00 +0000 (15:31 +0100)
files/lib/system/event/listener/ConversationUserActionRenameListener.class.php
files/lib/system/event/listener/ConversationUserMergeListener.class.php

index bdc02be4d31048cafabe2059b4a8dcba63ea6e75..97f8b1e69761305913f05e419db53bb611fca26a 100644 (file)
@@ -1,50 +1,27 @@
 <?php
 namespace wcf\system\event\listener;
-use wcf\system\WCF;
 
 /**
- * Updates the stored username on user rename.
+ * Updates the stored username during user rename.
  * 
  * @author     Alexander Ebert
- * @copyright  2001-2015 WoltLab GmbH
+ * @copyright  2001-2016 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf.conversation
  * @subpackage system.event.listener
  * @category   Community Framework
  */
-class ConversationUserActionRenameListener implements IParameterizedEventListener {
+class ConversationUserActionRenameListener extends AbstractUserActionRenameListener {
        /**
-        * @see \wcf\system\event\listener\IParameterizedEventListener::execute()
+        * @inheritDoc
         */
-       public function execute($eventObj, $className, $eventName, array &$parameters) {
-               $objects = $eventObj->getObjects();
-               $userID = $objects[0]->userID;
-               
-               $actionParameters = $eventObj->getParameters();
-               $username = $actionParameters['data']['username'];
-               
-               WCF::getDB()->beginTransaction();
-               
-               // conversations
-               $sql = "UPDATE  wcf".WCF_N."_conversation
-                       SET     username = ?
-                       WHERE   userID = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array($username, $userID));
-               
-               $sql = "UPDATE  wcf".WCF_N."_conversation
-                       SET     lastPoster = ?
-                       WHERE   lastPosterID = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array($username, $userID));
-               
-               // conversation messages
-               $sql = "UPDATE  wcf".WCF_N."_conversation_message
-                       SET     username = ?
-                       WHERE   userID = ?";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array($username, $userID));
-               
-               WCF::getDB()->commitTransaction();
-       }
+       protected $databaseTables = [
+               'wcf{WCF_N}_conversation',
+               'wcf{WCF_N}_conversation_message',
+               [
+                       'name' => 'wcf{WCF_N}_conversation',
+                       'userID' => 'lastPosterID',
+                       'username' => 'lastPoster'
+               ]
+       ];
 }
index 3a74c6cd21b4ecf18decc099789cdb3065026afe..cfe08395005626eb8c9c9ba68f3bb4d8e9a3ee5f 100644 (file)
@@ -1,57 +1,28 @@
 <?php
 namespace wcf\system\event\listener;
-use wcf\system\database\util\PreparedStatementConditionBuilder;
-use wcf\system\WCF;
 
 /**
  * Merges user conversations.
  * 
  * @author     Marcel Werk
- * @copyright  2001-2015 WoltLab GmbH
+ * @copyright  2001-2016 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    com.woltlab.wcf.conversation
  * @subpackage system.event.listener
  * @category   Community Framework
  */
-class ConversationUserMergeListener implements IParameterizedEventListener {
+class ConversationUserMergeListener extends AbstractUserMergeListener {
        /**
-        * @see \wcf\system\event\listener\IParameterizedEventListener::execute()
+        * @inheritDoc
         */
-       public function execute($eventObj, $className, $eventName, array &$parameters) {
-               // conversation
-               $conditions = new PreparedStatementConditionBuilder();
-               $conditions->add("userID IN (?)", array($eventObj->mergedUserIDs));
-               $sql = "UPDATE  wcf".WCF_N."_conversation
-                       SET     userID = ?
-                       ".$conditions;
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array_merge(array($eventObj->destinationUserID), $conditions->getParameters()));
-               
-               // conversation_to_user
-               $conditions = new PreparedStatementConditionBuilder();
-               $conditions->add("participantID IN (?)", array($eventObj->mergedUserIDs));
-               $sql = "UPDATE IGNORE   wcf".WCF_N."_conversation_to_user
-                       SET             participantID = ?
-                       ".$conditions;
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array_merge(array($eventObj->destinationUserID), $conditions->getParameters()));
-               
-               // conversation_message
-               $conditions = new PreparedStatementConditionBuilder();
-               $conditions->add("userID IN (?)", array($eventObj->mergedUserIDs));
-               $sql = "UPDATE  wcf".WCF_N."_conversation_message
-                       SET     userID = ?
-                       ".$conditions;
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array_merge(array($eventObj->destinationUserID), $conditions->getParameters()));
-               
-               // conversation_label
-               $conditions = new PreparedStatementConditionBuilder();
-               $conditions->add("userID IN (?)", array($eventObj->mergedUserIDs));
-               $sql = "UPDATE  wcf".WCF_N."_conversation_label
-                       SET     userID = ?
-                       ".$conditions;
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array_merge(array($eventObj->destinationUserID), $conditions->getParameters()));
-       }
+       protected $databaseTables = [
+               'wcf{WCF_N}_conversation',
+               'wcf{WCF_N}_conversation_message',
+               'wcf{WCF_N}_conversation_label',
+               [
+                       'name' => 'wcf{WCF_N}_conversation_to_user',
+                       'userID' => 'participantID',
+                       'ignore' => true
+               ]
+       ];
 }