From 37744d0552dd48d9789e612a2db33b8a39e4d0fb Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 22 Jan 2014 08:34:09 +0100 Subject: [PATCH] Fixes counter update when deleting comment with responses When deleting comments with responses, the object type processor is first called with the number of responses plus one (for the deleted comment itself). This call correctly corrects the number of comments for the relevant object. Afterwards, when deleting the responses, the objects' comment counters were updated again for each deleted response which causes a incorrect count because the counters were now updated twice for each response. Thus, we can simply ignore the counter update altogether in CommentResponseAction when deleting responses because the comment, they belong to, is deleted. Furthermore, there is no need for CommentResponseAction to update the response counter of those comments in this case because the comments will be deleted anyway. --- .../lib/data/comment/CommentAction.class.php | 4 ++- .../response/CommentResponseAction.class.php | 30 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php index fa46587930..d7c1fbc8db 100644 --- a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php +++ b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php @@ -110,7 +110,9 @@ class CommentAction extends AbstractDatabaseObjectAction { $commentResponseList->getConditionBuilder()->add('comment_response.commentID IN (?)', array($commentIDs)); $commentResponseList->readObjectIDs(); if (count($commentResponseList->getObjectIDs())) { - $action = new CommentResponseAction($commentResponseList->getObjectIDs(), 'delete'); + $action = new CommentResponseAction($commentResponseList->getObjectIDs(), 'delete', array( + 'ignoreCounters' => true + )); $action->executeAction(); } } diff --git a/wcfsetup/install/files/lib/data/comment/response/CommentResponseAction.class.php b/wcfsetup/install/files/lib/data/comment/response/CommentResponseAction.class.php index fdbeeb9860..98077b4191 100644 --- a/wcfsetup/install/files/lib/data/comment/response/CommentResponseAction.class.php +++ b/wcfsetup/install/files/lib/data/comment/response/CommentResponseAction.class.php @@ -56,6 +56,8 @@ class CommentResponseAction extends AbstractDatabaseObjectAction { return 0; } + $ignoreCounters = !empty($this->parameters['ignoreCounters']); + // read object type ids for comments $commentIDs = array(); foreach ($this->objects as $response) { @@ -77,27 +79,31 @@ class CommentResponseAction extends AbstractDatabaseObjectAction { $processors[$objectTypeID] = $objectType->getProcessor(); $responseIDs[$objectTypeID] = array(); } - - $processors[$objectTypeID]->updateCounter($comments[$response->commentID]->objectID, -1); $responseIDs[$objectTypeID][] = $response->responseID; - if (!isset($updateComments[$response->commentID])) { - $updateComments[$response->commentID] = 0; + if (!$ignoreCounters) { + $processors[$objectTypeID]->updateCounter($comments[$response->commentID]->objectID, -1); + + if (!isset($updateComments[$response->commentID])) { + $updateComments[$response->commentID] = 0; + } + + $updateComments[$response->commentID]++; } - - $updateComments[$response->commentID]++; } // remove responses $count = parent::delete(); // update comment responses and cached response ids - foreach ($comments as $comment) { - $commentEditor = new CommentEditor($comment); - $commentEditor->updateResponseIDs(); - $commentEditor->updateCounters(array( - 'responses' => -1 * $updateComments[$comment->commentID] - )); + if (!$ignoreCounters) { + foreach ($comments as $comment) { + $commentEditor = new CommentEditor($comment); + $commentEditor->updateResponseIDs(); + $commentEditor->updateCounters(array( + 'responses' => -1 * $updateComments[$comment->commentID] + )); + } } foreach ($responseIDs as $objectTypeID => $objectIDs) { -- 2.20.1