devel_rebuild_node_comment_statistics was removed without replacement

Created on 7 February 2021, about 4 years ago
Updated 3 April 2025, 4 days ago

Problem/Motivation

devel_rebuild_node_comment_statistics was removed in #1891070: Remove devel_rebuild_node_comment_statistics from the codebase β†’ because it referred to an outdated Drupal 7 database schema. It wasn't replaced with an equivalent feature in Drupal 8/9. A core issue was supposed to be created, but it doesn't appear to have been.

Proposed resolution

Incorporate similar functionality into \Drupal\comment\CommentStatistics.

Remaining tasks

Code.

User interface changes

Possible UI to run this?

API changes

None.

Data model changes

None.

Release notes snippet

TBD.

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

comment.module

Created by

πŸ‡ΊπŸ‡ΈUnited States danchadwick Boston

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡­πŸ‡Ί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.

Production build 0.71.5 2024