<?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'
+ ]
+ ];
}
<?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
+ ]
+ ];
}