diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index b6483ee..9d5510c 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1044,12 +1044,16 @@ function comment_entity_insert(EntityInterface $entity) { 'last_comment_uid', 'comment_count' )); + $execute_query = FALSE; foreach ($fields as $field_name => $detail) { // Skip fields that entity does not have. if (!$entity->getPropertyDefinition($field_name)) { continue; } // There is at least one comment field, the query needs to be executed. + $execute_query = TRUE; + // Get the user ID from the entity if it's set, or default to the + // currently logged in user. if ($entity instanceof EntityAuthorInterface) { $last_comment_uid = $entity->getAuthorId(); } @@ -1074,7 +1078,9 @@ function comment_entity_insert(EntityInterface $entity) { 'comment_count' => 0, )); } - $query->execute(); + if ($execute_query) { + $query->execute(); + } } } diff --git a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php index 9141048..0bf8ed1 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentStorageController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentStorageController.php @@ -98,6 +98,8 @@ public function updateEntityStatistics(CommentInterface $comment) { else { // Comments do not exist. $entity = entity_load($comment->entity_type->value, $comment->entity_id->value); + // Get the user ID from the entity if it's set, or default to the + // currently logged in user. if ($entity instanceof EntityAuthorInterface) { $last_comment_uid = $entity->getAuthorId(); } @@ -114,8 +116,6 @@ public function updateEntityStatistics(CommentInterface $comment) { // REQUEST_TIME. 'last_comment_timestamp' => ($entity instanceof EntityChangedInterface) ? $entity->getChangedTime() : REQUEST_TIME, 'last_comment_name' => '', - // Get the user ID from the entity if it's set, or default to the - // currently logged in user. 'last_comment_uid' => $last_comment_uid, )) ->condition('entity_id', $comment->entity_id->value)