From 25d97487b6a70dddc031a4cd97095e0b9a747f06 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 25 Mar 2014 09:42:46 +0100 Subject: [PATCH] Improves event listener accessibility of CommentAction Fixes #1644 --- .../lib/data/comment/CommentAction.class.php | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php index 7a19525f38..94fa72cb08 100644 --- a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php +++ b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php @@ -58,6 +58,18 @@ class CommentAction extends AbstractDatabaseObjectAction { */ protected $response = null; + /** + * comment object created by addComment() + * @var \wcf\data\comment\Comment + */ + public $createdComment = null; + + /** + * response object created by addResponse() + * @var \wcf\data\comment\response\CommentResponse + */ + public $createdResponse = null; + /** * @see \wcf\data\AbstractDatabaseObjectAction::delete() */ @@ -179,7 +191,7 @@ class CommentAction extends AbstractDatabaseObjectAction { */ public function addComment() { // create comment - $comment = CommentEditor::create(array( + $this->createdComment = CommentEditor::create(array( 'objectTypeID' => $this->parameters['data']['objectTypeID'], 'objectID' => $this->parameters['data']['objectID'], 'time' => TIME_NOW, @@ -196,22 +208,22 @@ class CommentAction extends AbstractDatabaseObjectAction { // fire activity event $objectType = ObjectTypeCache::getInstance()->getObjectType($this->parameters['data']['objectTypeID']); if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType.'.recentActivityEvent')) { - UserActivityEventHandler::getInstance()->fireEvent($objectType->objectType.'.recentActivityEvent', $comment->commentID); + UserActivityEventHandler::getInstance()->fireEvent($objectType->objectType.'.recentActivityEvent', $this->createdComment->commentID); } // fire notification event if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.notification')) { $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType.'.notification'); - $userID = $notificationObjectType->getOwnerID($comment->commentID); + $userID = $notificationObjectType->getOwnerID($this->createdComment->commentID); if ($userID != WCF::getUser()->userID) { - $notificationObject = new CommentUserNotificationObject($comment); + $notificationObject = new CommentUserNotificationObject($this->createdComment); UserNotificationHandler::getInstance()->fireEvent('comment', $objectType->objectType.'.notification', $notificationObject, array($userID)); } } return array( - 'template' => $this->renderComment($comment) + 'template' => $this->renderComment($this->createdComment) ); } @@ -243,7 +255,7 @@ class CommentAction extends AbstractDatabaseObjectAction { */ public function addResponse() { // create response - $response = CommentResponseEditor::create(array( + $this->createdResponse = CommentResponseEditor::create(array( 'commentID' => $this->comment->commentID, 'time' => TIME_NOW, 'userID' => WCF::getUser()->userID, @@ -254,9 +266,9 @@ class CommentAction extends AbstractDatabaseObjectAction { // update response data $responseIDs = $this->comment->getResponseIDs(); if (count($responseIDs) < 3) { - $responseIDs[] = $response->responseID; + $responseIDs[] = $this->createdResponse->responseID; } - $responses = $this->comment->responses + 1; + $responses = $this->comment->createdResponse + 1; // update comment $commentEditor = new CommentEditor($this->comment); @@ -271,12 +283,12 @@ class CommentAction extends AbstractDatabaseObjectAction { // fire activity event $objectType = ObjectTypeCache::getInstance()->getObjectType($this->comment->objectTypeID); if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType.'.response.recentActivityEvent')) { - UserActivityEventHandler::getInstance()->fireEvent($objectType->objectType.'.response.recentActivityEvent', $response->responseID); + UserActivityEventHandler::getInstance()->fireEvent($objectType->objectType.'.response.recentActivityEvent', $this->createdResponse->responseID); } // fire notification event if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.response.notification')) { - $notificationObject = new CommentResponseUserNotificationObject($response); + $notificationObject = new CommentResponseUserNotificationObject($this->createdResponse); if ($this->comment->userID != WCF::getUser()->userID) { UserNotificationHandler::getInstance()->fireEvent('commentResponse', $objectType->objectType.'.response.notification', $notificationObject, array($this->comment->userID)); } @@ -285,7 +297,7 @@ class CommentAction extends AbstractDatabaseObjectAction { if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.notification')) { $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType.'.notification'); $userID = $notificationObjectType->getOwnerID($this->comment->commentID); - + if ($userID != $this->comment->userID && $userID != WCF::getUser()->userID) { UserNotificationHandler::getInstance()->fireEvent('commentResponseOwner', $objectType->objectType.'.response.notification', $notificationObject, array($userID)); } @@ -294,7 +306,7 @@ class CommentAction extends AbstractDatabaseObjectAction { return array( 'commentID' => $this->comment->commentID, - 'template' => $this->renderResponse($response), + 'template' => $this->renderResponse($this->createdResponse), 'responses' => $responses ); } -- 2.20.1