- ππΊHungary szato
Same issue after migrating comments to D10: comment_count is set to 0 in comment_entity_statistics table. Furthermore, comment.maintain_entity_statistics isn't set to TRUE, results: users with 'access comments' can't see comments (these are not loaded), because of
$entity->get($field_name)->comment_count
is 0 in:
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/comme...I used CommentStatistics::update (I have only ~600 comments)
/** * Update comment statistics. */ function hook_update_N() { \Drupal::state()->set('comment.maintain_entity_statistics', TRUE); \Drupal::database()->truncate('comment_entity_statistics')->execute(); /** @var \Drupal\comment\CommentStatisticsInterface $commentStatistics */ $commentStatistics = \Drupal::service('comment.statistics'); /** @var \Drupal\comment\CommentInterface[] $comments */ $comments = \Drupal::entityTypeManager()->getStorage('comment')->loadMultiple(); foreach ($comments as $comment) { $commentStatistics->update($comment); } }
- ππΊHungary szato
I think we should display a warning message on 'Status report' page if 'comment.maintain_entity_statistics' state is not TRUE and if there are comment entities but no comment_count is set, or all is set to 0 in the comment_entity_statistics table. Adding a link in a warning report to an admin UI page with the possibility to run a batch process to call CommentStatistics::update for all comments.