diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index 112dfe6..3188473 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -158,14 +158,11 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { // Always invalidate the cache tag for the commented entity. if ($commented_entity = $this->getCommentedEntity()) { Cache::invalidateTags($commented_entity->getCacheTagsToInvalidate()); + // Update the {comment_entity_statistics} table prior to executing the hook. + \Drupal::service('comment.statistics')->update($commented_entity, array($this->getFieldName())); } $this->releaseThreadLock(); - // Update the {comment_entity_statistics} table prior to executing the hook. - $entity = $this->getCommentedEntity(); - if (!empty($entity)) { - \Drupal::service('comment.statistics')->update($entity, array($this->getFieldName())); - } } /** diff --git a/core/modules/comment/tests/src/Unit/Entity/CommentLockTest.php b/core/modules/comment/tests/src/Unit/Entity/CommentLockTest.php index dd9842a..021e7b6 100644 --- a/core/modules/comment/tests/src/Unit/Entity/CommentLockTest.php +++ b/core/modules/comment/tests/src/Unit/Entity/CommentLockTest.php @@ -85,13 +85,6 @@ public function testLocks() { $comment->expects($this->any()) ->method('getEntityType') ->will($this->returnValue($entity_type)); - $entity = $this->getMock('\Drupal\Core\Entity\ContentEntityInterface'); - $comment->expects($this->any()) - ->method('getCommentedEntity') - ->will($this->returnValue($entity)); - $comment->expects($this->any()) - ->method('getFieldName') - ->will($this->returnValue('')); $comment->expects($this->at(1)) ->method('get') ->with('status')