Use AbstractModificationLogHandler
authorMatthias Schmidt <gravatronics@live.com>
Wed, 23 Dec 2015 08:31:11 +0000 (09:31 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 23 Dec 2015 08:31:11 +0000 (09:31 +0100)
files/lib/data/conversation/ConversationAction.class.php
files/lib/data/modification/log/ConversationLogModificationLogList.class.php
files/lib/system/log/modification/ConversationModificationLogHandler.class.php

index 88cbc8f02b87c857f6ef734d3fd470665a035bbd..c1d79e7049002df7fff5ea2b41f58d4803a10efd 100644 (file)
@@ -31,13 +31,13 @@ use wcf\system\WCF;
  */
 class ConversationAction extends AbstractDatabaseObjectAction implements IClipboardAction, IVisitableObjectAction {
        /**
-        * @see \wcf\data\AbstractDatabaseObjectAction::$className
+        * @inheritDoc
         */
-       protected $className = 'wcf\data\conversation\ConversationEditor';
+       protected $className = ConversationEditor::class;
        
        /**
         * conversation object
-        * @var \wcf\data\conversation\ConversationEditor
+        * @var ConversationEditor
         */
        protected $conversation = null;
        
@@ -45,10 +45,10 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
         * list of conversation data modifications
         * @var array<array>
         */
-       protected $conversationData = array();
+       protected $conversationData = [];
        
        /**
-        * @see \wcf\data\AbstractDatabaseObjectAction::create()
+        * @inheritDoc
         */
        public function create() {
                // create conversation
@@ -64,15 +64,15 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) {
                        $data['attachments'] = count($this->parameters['attachmentHandler']);
                }
-               $conversation = call_user_func(array($this->className, 'create'), $data);
+               $conversation = call_user_func([$this->className, 'create'], $data);
                $conversationEditor = new ConversationEditor($conversation);
                
                if (!$conversation->isDraft) {
                        // save participants
-                       $conversationEditor->updateParticipants((!empty($this->parameters['participants']) ? $this->parameters['participants'] : array()), (!empty($this->parameters['invisibleParticipants']) ? $this->parameters['invisibleParticipants'] : array()));
+                       $conversationEditor->updateParticipants((!empty($this->parameters['participants']) ? $this->parameters['participants'] : []), (!empty($this->parameters['invisibleParticipants']) ? $this->parameters['invisibleParticipants'] : []));
                        
                        // add author
-                       $conversationEditor->updateParticipants(array($data['userID']));
+                       $conversationEditor->updateParticipants([$data['userID']]);
                        
                        // update conversation count
                        UserStorageHandler::getInstance()->reset($conversation->getParticipantIDs(), 'conversationCount');
@@ -83,11 +83,11 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                                WHERE   participantID = ?
                                        AND conversationID = ?";
                        $statement = WCF::getDB()->prepareStatement($sql);
-                       $statement->execute(array($data['time'], $data['userID'], $conversation->conversationID));
+                       $statement->execute([$data['time'], $data['userID'], $conversation->conversationID]);
                }
                else {
                        // update conversation count
-                       UserStorageHandler::getInstance()->reset(array($data['userID']), 'conversationCount');
+                       UserStorageHandler::getInstance()->reset([$data['userID']], 'conversationCount');
                }
                
                // update participant summary
@@ -100,23 +100,23 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                $messageData['userID'] = $this->parameters['data']['userID'];
                $messageData['username'] = $this->parameters['data']['username'];
                
-               $messageAction = new ConversationMessageAction(array(), 'create', array(
+               $messageAction = new ConversationMessageAction([], 'create', [
                        'data' => $messageData,
                        'conversation' => $conversation,
                        'isFirstPost' => true,
-                       'attachmentHandler' => (isset($this->parameters['attachmentHandler']) ? $this->parameters['attachmentHandler'] : null) 
-               ));
+                       'attachmentHandler' => (isset($this->parameters['attachmentHandler']) ? $this->parameters['attachmentHandler'] : null)
+               ]);
                $resultValues = $messageAction->executeAction();
                
                // update first message id
-               $conversationEditor->update(array(
+               $conversationEditor->update([
                        'firstMessageID' => $resultValues['returnValues']->messageID
-               ));
+               ]);
                
                $conversation->setFirstMessage($resultValues['returnValues']);
                if (!$conversation->isDraft) {
                        // fire notification event
-                       $notificationRecipients = array_merge((!empty($this->parameters['participants']) ? $this->parameters['participants'] : array()), (!empty($this->parameters['invisibleParticipants']) ? $this->parameters['invisibleParticipants'] : array()));
+                       $notificationRecipients = array_merge((!empty($this->parameters['participants']) ? $this->parameters['participants'] : []), (!empty($this->parameters['invisibleParticipants']) ? $this->parameters['invisibleParticipants'] : []));
                        UserNotificationHandler::getInstance()->fireEvent('conversation', 'com.woltlab.wcf.conversation.notification', new ConversationUserNotificationObject($conversation), $notificationRecipients);
                }
                
@@ -124,12 +124,12 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
        }
        
        /**
-        * @see \wcf\data\IDeleteAction::delete()
+        * @inheritDoc
         */
        public function delete() {
                // deletes messages
                $messageList = new ConversationMessageList();
-               $messageList->getConditionBuilder()->add('conversation_message.conversationID IN (?)', array($this->objectIDs));
+               $messageList->getConditionBuilder()->add('conversation_message.conversationID IN (?)', [$this->objectIDs]);
                $messageList->readObjectIDs();
                $action = new ConversationMessageAction($messageList->getObjectIDs(), 'delete');
                $action->executeAction();
@@ -139,19 +139,19 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                
                if (!empty($this->objectIDs)) {
                        // delete notifications
-                       UserNotificationHandler::getInstance()->deleteNotifications('conversation', 'com.woltlab.wcf.conversation.notification', array(), $this->objectIDs);
+                       UserNotificationHandler::getInstance()->deleteNotifications('conversation', 'com.woltlab.wcf.conversation.notification', [], $this->objectIDs);
                        
                        // remove modification logs
-                       ConversationModificationLogHandler::getInstance()->remove($this->objectIDs);
+                       ConversationModificationLogHandler::getInstance()->deleteLogs($this->objectIDs);
                }
        }
        
        /**
-        * @see \wcf\data\AbstractDatabaseObjectAction::update()
+        * @inheritDoc
         */
        public function update() {
-               if (!isset($this->parameters['participants'])) $this->parameters['participants'] = array();
-               if (!isset($this->parameters['invisibleParticipants'])) $this->parameters['invisibleParticipants'] = array();
+               if (!isset($this->parameters['participants'])) $this->parameters['participants'] = [];
+               if (!isset($this->parameters['invisibleParticipants'])) $this->parameters['invisibleParticipants'] = [];
                
                // count participants
                if (!empty($this->parameters['participants'])) {
@@ -166,7 +166,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                                // get current participants
                                $participantIDs = $conversation->getParticipantIDs();
                                
-                               $conversation->updateParticipants((!empty($this->parameters['participants']) ? $this->parameters['participants'] : array()), (!empty($this->parameters['invisibleParticipants']) ? $this->parameters['invisibleParticipants'] : array()));
+                               $conversation->updateParticipants((!empty($this->parameters['participants']) ? $this->parameters['participants'] : []), (!empty($this->parameters['invisibleParticipants']) ? $this->parameters['invisibleParticipants'] : []));
                                $conversation->updateParticipantSummary();
                                
                                // check if new participants have been added
@@ -185,7 +185,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                        if (isset($this->parameters['data']['isDraft'])) {
                                if ($conversation->isDraft && !$this->parameters['data']['isDraft']) {
                                        // add author
-                                       $conversation->updateParticipants(array($conversation->userID));
+                                       $conversation->updateParticipants([$conversation->userID]);
                                        
                                        // update conversation count
                                        UserStorageHandler::getInstance()->reset($conversation->getParticipantIDs(), 'unreadConversationCount');
@@ -196,7 +196,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
        }
        
        /**
-        * @see \wcf\data\IVisitableObjectAction::markAsRead()
+        * @inheritDoc
         */
        public function markAsRead() {
                if (empty($this->parameters['visitTime'])) {
@@ -207,7 +207,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                        $this->readObjects();
                }
                
-               $conversationIDs = array();
+               $conversationIDs = [];
                $sql = "UPDATE  wcf".WCF_N."_conversation_to_user
                        SET     lastVisitTime = ?
                        WHERE   participantID = ?
@@ -215,27 +215,27 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                $statement = WCF::getDB()->prepareStatement($sql);
                WCF::getDB()->beginTransaction();
                foreach ($this->objects as $conversation) {
-                       $statement->execute(array(
+                       $statement->execute([
                                $this->parameters['visitTime'],
                                WCF::getUser()->userID,
                                $conversation->conversationID
-                       ));
+                       ]);
                        $conversationIDs[] = $conversation->conversationID;
                }
                WCF::getDB()->commitTransaction();
                
                // reset storage
-               UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'unreadConversationCount');
+               UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'unreadConversationCount');
                
                // mark notifications as confirmed
                if (!empty($conversationIDs)) {
                        // conversation start notification
                        $conditionBuilder = new PreparedStatementConditionBuilder();
-                       $conditionBuilder->add('notification.eventID = ?', array(UserNotificationHandler::getInstance()->getEvent('com.woltlab.wcf.conversation.notification', 'conversation')->eventID));
+                       $conditionBuilder->add('notification.eventID = ?', [UserNotificationHandler::getInstance()->getEvent('com.woltlab.wcf.conversation.notification', 'conversation')->eventID]);
                        $conditionBuilder->add('notification.objectID = conversation.conversationID');
-                       $conditionBuilder->add('notification.userID = ?', array(WCF::getUser()->userID));
-                       $conditionBuilder->add('conversation.conversationID IN (?)', array($conversationIDs));
-                       $conditionBuilder->add('conversation.time <= ?', array($this->parameters['visitTime']));
+                       $conditionBuilder->add('notification.userID = ?', [WCF::getUser()->userID]);
+                       $conditionBuilder->add('conversation.conversationID IN (?)', [$conversationIDs]);
+                       $conditionBuilder->add('conversation.time <= ?', [$this->parameters['visitTime']]);
                        
                        $sql = "SELECT          conversation.conversationID
                                FROM            wcf".WCF_N."_conversation conversation,
@@ -243,22 +243,22 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                                ".$conditionBuilder;
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute($conditionBuilder->getParameters());
-                       $notificationObjectIDs = array();
+                       $notificationObjectIDs = [];
                        while ($row = $statement->fetchArray()) {
                                $notificationObjectIDs[] = $row['conversationID'];
                        }
                        
                        if (!empty($notificationObjectIDs)) {
-                               UserNotificationHandler::getInstance()->markAsConfirmed('conversation', 'com.woltlab.wcf.conversation.notification', array(WCF::getUser()->userID), $notificationObjectIDs);
+                               UserNotificationHandler::getInstance()->markAsConfirmed('conversation', 'com.woltlab.wcf.conversation.notification', [WCF::getUser()->userID], $notificationObjectIDs);
                        }
                        
                        // conversation reply notification
                        $conditionBuilder = new PreparedStatementConditionBuilder();
-                       $conditionBuilder->add('notification.eventID = ?', array(UserNotificationHandler::getInstance()->getEvent('com.woltlab.wcf.conversation.message.notification', 'conversationMessage')->eventID));
+                       $conditionBuilder->add('notification.eventID = ?', [UserNotificationHandler::getInstance()->getEvent('com.woltlab.wcf.conversation.message.notification', 'conversationMessage')->eventID]);
                        $conditionBuilder->add('notification.objectID = conversation_message.messageID');
-                       $conditionBuilder->add('notification.userID = ?', array(WCF::getUser()->userID));
-                       $conditionBuilder->add('conversation_message.conversationID IN (?)', array($conversationIDs));
-                       $conditionBuilder->add('conversation_message.time <= ?', array($this->parameters['visitTime']));
+                       $conditionBuilder->add('notification.userID = ?', [WCF::getUser()->userID]);
+                       $conditionBuilder->add('conversation_message.conversationID IN (?)', [$conversationIDs]);
+                       $conditionBuilder->add('conversation_message.time <= ?', [$this->parameters['visitTime']]);
                        
                        $sql = "SELECT          conversation_message.messageID
                                FROM            wcf".WCF_N."_conversation_message conversation_message,
@@ -266,13 +266,13 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                                ".$conditionBuilder;
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute($conditionBuilder->getParameters());
-                       $notificationObjectIDs = array();
+                       $notificationObjectIDs = [];
                        while ($row = $statement->fetchArray()) {
                                $notificationObjectIDs[] = $row['messageID'];
                        }
                        
                        if (!empty($notificationObjectIDs)) {
-                               UserNotificationHandler::getInstance()->markAsConfirmed('conversationMessage', 'com.woltlab.wcf.conversation.message.notification', array(WCF::getUser()->userID), $notificationObjectIDs);
+                               UserNotificationHandler::getInstance()->markAsConfirmed('conversationMessage', 'com.woltlab.wcf.conversation.message.notification', [WCF::getUser()->userID], $notificationObjectIDs);
                        }
                }
                
@@ -280,9 +280,9 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                        $this->unmarkItems($conversationIDs);
                }
                
-               $returnValues = array(
+               $returnValues = [
                        'totalCount' => ConversationHandler::getInstance()->getUnreadConversationCount(null, true)
-               );
+               ];
                
                if (count($conversationIDs) == 1) {
                        $returnValues['markAsRead'] = reset($conversationIDs);
@@ -292,7 +292,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
        }
        
        /**
-        * @see \wcf\data\IVisitableObjectAction::validateMarkAsRead()
+        * @inheritDoc
         */
        public function validateMarkAsRead() {
                // visitTime might not be in the future
@@ -308,7 +308,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                }
                
                // check participation
-               $conversationIDs = array();
+               $conversationIDs = [];
                foreach ($this->objects as $conversation) {
                        $conversationIDs[] = $conversation->conversationID;
                }
@@ -330,27 +330,29 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                        SET     lastVisitTime = ?
                        WHERE   participantID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array(
+               $statement->execute([
                        TIME_NOW,
                        WCF::getUser()->userID
-               ));
+               ]);
                
                // reset storage
-               UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'unreadConversationCount');
+               UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'unreadConversationCount');
                
                // delete obsolete notifications
-               UserNotificationHandler::getInstance()->deleteNotifications('conversation', 'com.woltlab.wcf.conversation.notification', array(WCF::getUser()->userID));
-               UserNotificationHandler::getInstance()->deleteNotifications('conversationMessage', 'com.woltlab.wcf.conversation.message.notification', array(WCF::getUser()->userID));
+               UserNotificationHandler::getInstance()->deleteNotifications('conversation', 'com.woltlab.wcf.conversation.notification', [WCF::getUser()->userID]);
+               UserNotificationHandler::getInstance()->deleteNotifications('conversationMessage', 'com.woltlab.wcf.conversation.message.notification', [WCF::getUser()->userID]);
                
-               return array(
+               return [
                        'markAllAsRead' => true
-               );
+               ];
        }
        
        /**
         * Validates the markAllAsRead action.
         */
-       public function validateMarkAllAsRead() {}
+       public function validateMarkAllAsRead() {
+               // does nothing
+       }
        
        /**
         * Validates user access for label management.
@@ -367,17 +369,17 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
         * @return      array
         */
        public function getLabelManagement() {
-               WCF::getTPL()->assign(array(
+               WCF::getTPL()->assign([
                        'cssClassNames' => ConversationLabel::getLabelCssClassNames(),
                        'labelList' => ConversationLabel::getLabelsByUser()
-               ));
+               ]);
                
-               return array(
+               return [
                        'actionName' => 'getLabelManagement',
                        'template' => WCF::getTPL()->fetch('conversationLabelManagement'),
                        'maxLabels' => WCF::getSession()->getPermission('user.conversation.maxLabels'),
                        'labelCount' => count(ConversationLabel::getLabelsByUser())
-               );
+               ];
        }
        
        /**
@@ -385,7 +387,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
         */
        public function validateGetMessagePreview() {
                $this->conversation = $this->getSingleObject();
-               if (!Conversation::isParticipant(array($this->conversation->conversationID))) {
+               if (!Conversation::isParticipant([$this->conversation->conversationID])) {
                        throw new PermissionDeniedException();
                }
        }
@@ -393,21 +395,21 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
        /**
         * Returns a preview of a message in a specific conversation.
         * 
-        * @return      array
+        * @return      string[]
         */
        public function getMessagePreview() {
                $messageList = new SimplifiedViewableConversationMessageList();
                
-               $messageList->getConditionBuilder()->add("conversation_message.messageID = ?", array($this->conversation->firstMessageID));
+               $messageList->getConditionBuilder()->add("conversation_message.messageID = ?", [$this->conversation->firstMessageID]);
                $messageList->readObjects();
                $messages = $messageList->getObjects();
                
-               WCF::getTPL()->assign(array(
+               WCF::getTPL()->assign([
                        'message' => reset($messages)
-               ));
-               return array(
+               ]);
+               return [
                        'template' => WCF::getTPL()->fetch('conversationMessagePreview')
-               );
+               ];
        }
        
        /**
@@ -438,7 +440,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
         */
        public function close() {
                foreach ($this->objects as $conversation) {
-                       $conversation->update(array('isClosed' => 1));
+                       $conversation->update(['isClosed' => 1]);
                        $this->addConversationData($conversation->getDecoratedObject(), 'isClosed', 1);
                        
                        ConversationModificationLogHandler::getInstance()->close($conversation->getDecoratedObject());
@@ -477,7 +479,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
         */
        public function open() {
                foreach ($this->objects as $conversation) {
-                       $conversation->update(array('isClosed' => 0));
+                       $conversation->update(['isClosed' => 0]);
                        $this->addConversationData($conversation->getDecoratedObject(), 'isClosed', 0);
                        
                        ConversationModificationLogHandler::getInstance()->open($conversation->getDecoratedObject());
@@ -514,18 +516,18 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                        WHERE   conversationID = ?
                                AND participantID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array(
+               $statement->execute([
                        current($this->objectIDs),
                        WCF::getUser()->userID
-               ));
+               ]);
                $row = $statement->fetchArray();
                
                WCF::getTPL()->assign('hideConversation', $row['hideConversation']);
                
-               return array(
+               return [
                        'actionName' => 'getLeaveForm',
                        'template' => WCF::getTPL()->fetch('conversationLeave')
-               );
+               ];
        }
        
        /**
@@ -533,7 +535,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
         */
        public function validateHideConversation() {
                $this->parameters['hideConversation'] = (isset($this->parameters['hideConversation'])) ? intval($this->parameters['hideConversation']) : null;
-               if ($this->parameters['hideConversation'] === null || !in_array($this->parameters['hideConversation'], array(Conversation::STATE_DEFAULT, Conversation::STATE_HIDDEN, Conversation::STATE_LEFT))) {
+               if ($this->parameters['hideConversation'] === null || !in_array($this->parameters['hideConversation'], [Conversation::STATE_DEFAULT, Conversation::STATE_HIDDEN, Conversation::STATE_LEFT])) {
                        throw new UserInputException('hideConversation');
                }
                
@@ -550,7 +552,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
        /**
         * Hides or restores conversations.
         * 
-        * @return      array
+        * @return      string[]
         */
        public function hideConversation() {
                $sql = "UPDATE  wcf".WCF_N."_conversation_to_user
@@ -561,19 +563,19 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                
                WCF::getDB()->beginTransaction();
                foreach ($this->objectIDs as $conversationID) {
-                       $statement->execute(array(
+                       $statement->execute([
                                $this->parameters['hideConversation'],
                                $conversationID,
                                WCF::getUser()->userID
-                       ));
+                       ]);
                }
                WCF::getDB()->commitTransaction();
                
                // reset user's conversation counters if user leaves conversation
                // permanently
                if ($this->parameters['hideConversation'] == Conversation::STATE_LEFT) {
-                       UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'conversationCount');
-                       UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'unreadConversationCount');
+                       UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'conversationCount');
+                       UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'unreadConversationCount');
                }
                
                // add modification log entry
@@ -595,9 +597,9 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                        
                        // delete conversation if all users have left it
                        $conditionBuilder = new PreparedStatementConditionBuilder();
-                       $conditionBuilder->add('conversation.conversationID IN (?)', array($this->objectIDs));
+                       $conditionBuilder->add('conversation.conversationID IN (?)', [$this->objectIDs]);
                        $conditionBuilder->add('conversation_to_user.conversationID IS NULL');
-                       $conversationIDs = array();
+                       $conversationIDs = [];
                        $sql = "SELECT          DISTINCT conversation.conversationID
                                FROM            wcf".WCF_N."_conversation conversation
                                LEFT JOIN       wcf".WCF_N."_conversation_to_user conversation_to_user
@@ -616,10 +618,10 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                        }
                }
                
-               return array(
+               return [
                        'actionName' => 'hideConversation',
                        'redirectURL' => LinkHandler::getInstance()->getLink('ConversationList')
-               );
+               ];
        }
        
        /**
@@ -641,7 +643,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                $unreadConversationList->sqlOrderBy = 'conversation.lastPostTime DESC';
                $unreadConversationList->readObjects();
                
-               $conversations = array();
+               $conversations = [];
                $count = 0;
                foreach ($unreadConversationList as $conversation) {
                        $conversations[] = $conversation;
@@ -660,19 +662,19 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                        }
                }
                
-               WCF::getTPL()->assign(array(
+               WCF::getTPL()->assign([
                        'conversations' => $conversations
-               ));
+               ]);
                
                $totalCount = ConversationHandler::getInstance()->getUnreadConversationCount();
                if ($count < 5 && $count < $totalCount) {
-                       UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'unreadConversationCount');
+                       UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'unreadConversationCount');
                }
                
-               return array(
+               return [
                        'template' => WCF::getTPL()->fetch('conversationListUserPanel'),
                        'totalCount' => $totalCount
-               );
+               ];
        }
        
        /**
@@ -694,7 +696,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
         */
        public function validateGetAddParticipantsForm() {
                $this->conversation = $this->getSingleObject();
-               if (!Conversation::isParticipant(array($this->conversation->conversationID)) || !$this->conversation->canAddParticipants()) {
+               if (!Conversation::isParticipant([$this->conversation->conversationID]) || !$this->conversation->canAddParticipants()) {
                        throw new PermissionDeniedException();
                }
        }
@@ -705,11 +707,11 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
         * @return      array
         */
        public function getAddParticipantsForm() {
-               return array(
+               return [
                        'excludedSearchValues' => $this->conversation->getParticipantNames(),
                        'maxItems' => WCF::getSession()->getPermission('user.conversation.maxParticipants') - $this->conversation->participants,
                        'template' => WCF::getTPL()->fetch('conversationAddParticipants')
-               );
+               ];
        }
        
        /**
@@ -735,43 +737,43 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                        $errorMessage = '';
                        foreach ($e->getType() as $type) {
                                if (!empty($errorMessage)) $errorMessage .= ' ';
-                               $errorMessage .= WCF::getLanguage()->getDynamicVariable('wcf.conversation.participants.error.'.$type['type'], array('errorData' => array('username' => $type['username'])));
+                               $errorMessage .= WCF::getLanguage()->getDynamicVariable('wcf.conversation.participants.error.'.$type['type'], ['errorData' => ['username' => $type['username']]]);
                        }
                        
-                       return array(
+                       return [
                                'actionName' => 'addParticipants',
                                'errorMessage' => $errorMessage
-                       );
+                       ];
                }
                
                // validate limit
                $newCount = $this->conversation->participants + count($participantIDs);
                if ($newCount > WCF::getSession()->getPermission('user.conversation.maxParticipants')) {
-                       return array(
+                       return [
                                'actionName' => 'addParticipants',
                                'errorMessage' => WCF::getLanguage()->getDynamicVariable('wcf.conversation.participants.error.tooManyParticipants')
-                       );
+                       ];
                }
                
                $count = 0;
                $successMessage = '';
                if (!empty($participantIDs)) {
                        // check for already added participants
-                       $data = array();
+                       $data = [];
                        if ($this->conversation->isDraft) {
                                $draftData = unserialize($this->conversation->draftData);
                                $draftData['participants'] = array_merge($draftData['participants'], $participantIDs);
-                               $data = array('data' => array('draftData' => serialize($draftData)));
+                               $data = ['data' => ['draftData' => serialize($draftData)]];
                        }
                        else {
-                               $data = array('participants' => $participantIDs);
+                               $data = ['participants' => $participantIDs];
                        }
                        
-                       $conversationAction = new ConversationAction(array($this->conversation), 'update', $data);
+                       $conversationAction = new ConversationAction([$this->conversation], 'update', $data);
                        $conversationAction->executeAction();
                        
                        $count = count($participantIDs);
-                       $successMessage = WCF::getLanguage()->getDynamicVariable('wcf.conversation.edit.addParticipants.success', array('count' => $count));
+                       $successMessage = WCF::getLanguage()->getDynamicVariable('wcf.conversation.edit.addParticipants.success', ['count' => $count]);
                        
                        ConversationModificationLogHandler::getInstance()->addParticipants($this->conversation->getDecoratedObject(), $participantIDs);
                        
@@ -781,10 +783,10 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                        }
                }
                
-               return array(
+               return [
                        'count' => $count,
                        'successMessage' => $successMessage
-               );
+               ];
        }
        
        /**
@@ -805,7 +807,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                }
                
                // validate participants
-               if ($this->parameters['userID'] == WCF::getUser()->userID || !Conversation::isParticipant(array($this->conversation->conversationID)) || !Conversation::isParticipant(array($this->conversation->conversationID), $this->parameters['userID'])) {
+               if ($this->parameters['userID'] == WCF::getUser()->userID || !Conversation::isParticipant([$this->conversation->conversationID]) || !Conversation::isParticipant([$this->conversation->conversationID], $this->parameters['userID'])) {
                        throw new PermissionDeniedException();
                }
                
@@ -821,11 +823,11 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                ConversationModificationLogHandler::getInstance()->removeParticipant($this->conversation->getDecoratedObject(), $this->parameters['userID']);
                
                // reset storage
-               UserStorageHandler::getInstance()->reset(array($this->parameters['userID']), 'unreadConversationCount');
+               UserStorageHandler::getInstance()->reset([$this->parameters['userID']], 'unreadConversationCount');
                
-               return array(
+               return [
                        'userID' => $this->parameters['userID']
-               );
+               ];
        }
        
        /**
@@ -838,7 +840,7 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                
                // collect number of messages for each conversation
                $conditionBuilder = new PreparedStatementConditionBuilder();
-               $conditionBuilder->add('conversation_message.conversationID IN (?)', array($this->objectIDs));
+               $conditionBuilder->add('conversation_message.conversationID IN (?)', [$this->objectIDs]);
                $sql = "SELECT          conversationID, COUNT(messageID) AS messages, SUM(attachments) AS attachments
                        FROM            wcf".WCF_N."_conversation_message conversation_message
                        ".$conditionBuilder."
@@ -846,20 +848,20 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
                $statement = WCF::getDB()->prepareStatement($sql);
                $statement->execute($conditionBuilder->getParameters());
                
-               $objectIDs = array();
+               $objectIDs = [];
                while ($row = $statement->fetchArray()) {
                        if (!$row['messages']) {
                                continue;
                        }
                        $objectIDs[] = $row['conversationID'];
                        
-                       $conversationEditor = new ConversationEditor(new Conversation(null, array(
+                       $conversationEditor = new ConversationEditor(new Conversation(null, [
                                'conversationID' => $row['conversationID']
-                       )));
-                       $conversationEditor->update(array(
+                       ]));
+                       $conversationEditor->update([
                                'attachments' => $row['attachments'],
                                'replies' => $row['messages'] - 1
-                       ));
+                       ]);
                        $conversationEditor->updateFirstMessage();
                        $conversationEditor->updateLastMessage();
                }
@@ -875,13 +877,13 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
        /**
         * Adds conversation modification data.
         * 
-        * @param       \wcf\data\conversation\Conversation     $conversation
-        * @param       string                                  $key
-        * @param       mixed                                   $value
+        * @param       Conversation    $conversation
+        * @param       string          $key
+        * @param       mixed           $value
         */
        protected function addConversationData(Conversation $conversation, $key, $value) {
                if (!isset($this->conversationData[$conversation->conversationID])) {
-                       $this->conversationData[$conversation->conversationID] = array();
+                       $this->conversationData[$conversation->conversationID] = [];
                }
                
                $this->conversationData[$conversation->conversationID][$key] = $value;
@@ -893,17 +895,17 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
         * @return      array<array>
         */
        protected function getConversationData() {
-               return array(
+               return [
                        'conversationData' => $this->conversationData
-               );
+               ];
        }
        
        /**
         * Unmarks conversations.
         * 
-        * @param       array<integer>          $conversationIDs
+        * @param       integer[]               $conversationIDs
         */
-       protected function unmarkItems(array $conversationIDs = array()) {
+       protected function unmarkItems(array $conversationIDs = []) {
                if (empty($conversationIDs)) {
                        $conversationIDs = $this->objectIDs;
                }
index 0b9f9b4d3c9a30df76c225075777245a0ee004ca..1ff9332155f923a541968f23a71e5cec122c7e20 100644 (file)
@@ -24,50 +24,47 @@ class ConversationLogModificationLogList extends ModificationLogList {
        
        /**
         * conversation object
-        * @var \wcf\data\conversation\Conversation
+        * @var Conversation
         */
        public $conversation = null;
        
        /**
-        * @see \wbb\data\DatabaseObjectList::__construct()
+        * @inheritDoc
         */
        public function __construct() {
                parent::__construct();
                
-               // get object types
-               $conversationObjectType = ConversationModificationLogHandler::getInstance()->getObjectType('com.woltlab.wcf.conversation.conversation');
-               $this->conversationObjectTypeID = $conversationObjectType->objectTypeID;
+               $this->conversationObjectTypeID = ConversationModificationLogHandler::getInstance()->getObjectType()->objectTypeID;
        }
        
        /**
         * Initializes the conversation log modification log list.
         * 
-        * @param       \wcf\data\conversation\Conversation     $conversation
+        * @param       Conversation    $conversation
         */
        public function setConversation(Conversation $conversation) {
                $this->conversation = $conversation;
        }
        
        /**
-        * @see \wcf\data\DatabaseObjectList::countObjects()
+        * @inheritDoc
         */
        public function countObjects() {
-               $sql = "SELECT  COUNT(modification_log.logID) AS count
+               $sql = "SELECT  COUNT(modification_log.logID)
                        FROM    wcf".WCF_N."_modification_log modification_log
                        WHERE   modification_log.objectTypeID = ?
                                AND modification_log.objectID = ?";
                $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array(
+               $statement->execute([
                        $this->conversationObjectTypeID,
                        $this->conversation->conversationID
-               ));
-               $row = $statement->fetchArray();
+               ]);
                
-               return $row['count'];
+               return $statement->fetchColumn();
        }
        
        /**
-        * @see \wcf\data\DatabaseObjectList::readObjects()
+        * @inheritDoc
         */
        public function readObjects() {
                $sql = "SELECT  modification_log.*
@@ -76,14 +73,14 @@ class ConversationLogModificationLogList extends ModificationLogList {
                                AND modification_log.objectID = ?
                        ".(!empty($this->sqlOrderBy) ? "ORDER BY ".$this->sqlOrderBy : '');
                $statement = WCF::getDB()->prepareStatement($sql, $this->sqlLimit, $this->sqlOffset);
-               $statement->execute(array(
+               $statement->execute([
                        $this->conversationObjectTypeID,
                        $this->conversation->conversationID
-               ));
+               ]);
                $this->objects = $statement->fetchObjects(($this->objectClassName ?: $this->className));
                
                // use table index as array index
-               $objects = $userIDs = [ ];
+               $objects = $userIDs = [];
                foreach ($this->objects as $object) {
                        $objectID = $object->{$this->getDatabaseTableIndexName()};
                        $objects[$objectID] = $object;
@@ -112,10 +109,10 @@ class ConversationLogModificationLogList extends ModificationLogList {
         * will be returned and removed from collection.
         * 
         * @param       integer         $time
-        * @return      array<\wcf\data\modification\log\ViewableConversationModificationLog>
+        * @return      ViewableConversationModificationLog[]
         */
        public function getEntriesUntil($time) {
-               $entries = array();
+               $entries = [];
                foreach ($this->objects as $index => $entry) {
                        if ($entry->time < $time) {
                                $entries[] = $entry;
index b6ed2c0a2007d508f0d3a493aa9e6072ad8e2232..824b15e8b074e9e57edc8b988855d365daa9c88d 100644 (file)
@@ -14,34 +14,39 @@ use wcf\data\user\UserList;
  * @subpackage system.log.modification
  * @category   Community Framework
  */
-class ConversationModificationLogHandler extends ModificationLogHandler {
+class ConversationModificationLogHandler extends AbstractModificationLogHandler {
+       /**
+        * @inheritDoc
+        */
+       protected $objectTypeName = 'com.woltlab.wcf.conversation.conversation';
+       
        /**
         * Adds a log entry for newly added conversation participants.
         * 
-        * @param       \wcf\data\conversation\Conversation     $conversation
-        * @param       array<integer>                          $participantIDs
+        * @param       Conversation    $conversation
+        * @param       integer[]       $participantIDs
         */
        public function addParticipants(Conversation $conversation, array $participantIDs) {
-               $participants = array();
+               $participants = [];
                $userList = new UserList();
                $userList->setObjectIDs($participantIDs);
                $userList->readObjects();
                foreach ($userList as $user) {
-                       $participants[] = array(
+                       $participants[] = [
                                'userID' => $user->userID,
                                'username' => $user->username
-                       );
+                       ];
                }
                
-               $this->add($conversation, 'addParticipants', array(
+               $this->add($conversation, 'addParticipants', [
                        'participants' => $participants
-               ));
+               ]);
        }
        
        /**
         * Adds a log entry for conversation close.
         * 
-        * @param       \wcf\data\conversation\Conversation     $conversation
+        * @param       Conversation    $conversation
         */
        public function close(Conversation $conversation) {
                $this->add($conversation, 'close');
@@ -50,7 +55,7 @@ class ConversationModificationLogHandler extends ModificationLogHandler {
        /**
         * Adds a log entry for conversation open.
         * 
-        * @param       \wcf\data\conversation\Conversation     $conversation
+        * @param       Conversation    $conversation
         */
        public function open(Conversation $conversation) {
                $this->add($conversation, 'open');
@@ -59,7 +64,7 @@ class ConversationModificationLogHandler extends ModificationLogHandler {
        /**
         * Adds a log entry for conversation leave.
         * 
-        * @param       \wcf\data\conversation\Conversation     $conversation
+        * @param       Conversation    $conversation
         */
        public function leave(Conversation $conversation) {
                $this->add($conversation, 'leave');
@@ -68,35 +73,36 @@ class ConversationModificationLogHandler extends ModificationLogHandler {
        /**
         * Adds a log entry for a removed participant.
         * 
-        * @param       \wcf\data\conversation\Conversation     $conversation
-        * @param       integer                                 $userID
+        * @param       Conversation    $conversation
+        * @param       integer         $userID
         */
        public function removeParticipant(Conversation $conversation, $userID) {
                $user = new User($userID);
-               $this->add($conversation, 'removeParticipant', array(
+               $this->add($conversation, 'removeParticipant', [
                        'userID' => $userID,
                        'username' => $user->username
-               ));
+               ]);
        }
        
        /**
         * Adds a conversation modification log entry.
         * 
-        * @param       \wcf\data\conversation\Conversation     $conversation
-        * @param       string                                  $action
-        * @param       array                                   $additionalData
+        * @param       Conversation    $conversation
+        * @param       string          $action
+        * @param       array           $additionalData
         */
-       public function add(Conversation $conversation, $action, array $additionalData = array()) {
-               parent::_add('com.woltlab.wcf.conversation.conversation', $conversation->conversationID, $action, $additionalData);
+       public function add(Conversation $conversation, $action, array $additionalData = []) {
+               $this->createLog($action, $conversation->conversationID, null, $additionalData);
        }
        
        /**
         * Removes the conversation log entries of the conversations with the given
         * ids.
         * 
-        * @param       array<integer>          $objectIDs
+        * @param       integer[]       $objectIDs
+        * @deprecated  since 2.2, use deleteLogs()
         */
        public function remove(array $objectIDs) {
-               parent::_remove('com.woltlab.wcf.conversation.conversation', $objectIDs);
+               $this->deleteLogs($objectIDs);
        }
 }