From: Matthias Schmidt Date: Sat, 27 Feb 2016 14:31:00 +0000 (+0100) Subject: Use new event listeners for user merge/rename X-Git-Tag: 3.0.0_Beta_1~153 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ba308511c4a312d6cb0da548743d71bbc2091861;p=GitHub%2FWoltLab%2Fcom.woltlab.wcf.conversation.git Use new event listeners for user merge/rename --- diff --git a/files/lib/system/event/listener/ConversationUserActionRenameListener.class.php b/files/lib/system/event/listener/ConversationUserActionRenameListener.class.php index bdc02be..97f8b1e 100644 --- a/files/lib/system/event/listener/ConversationUserActionRenameListener.class.php +++ b/files/lib/system/event/listener/ConversationUserActionRenameListener.class.php @@ -1,50 +1,27 @@ * @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' + ] + ]; } diff --git a/files/lib/system/event/listener/ConversationUserMergeListener.class.php b/files/lib/system/event/listener/ConversationUserMergeListener.class.php index 3a74c6c..cfe0839 100644 --- a/files/lib/system/event/listener/ConversationUserMergeListener.class.php +++ b/files/lib/system/event/listener/ConversationUserMergeListener.class.php @@ -1,57 +1,28 @@ * @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 + ] + ]; }