From: Matthias Schmidt Date: Wed, 22 Jan 2014 07:34:09 +0000 (+0100) Subject: Fixes counter update when deleting comment with responses X-Git-Tag: 2.0.2~13^2~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=37744d0552dd48d9789e612a2db33b8a39e4d0fb;p=GitHub%2FWoltLab%2FWCF.git 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. --- 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) {