function forum_update_10101

Same name in other branches
  1. 11.x core/modules/forum/forum.install \forum_update_10101()

Repopulate the forum index table.

File

core/modules/forum/forum.install, line 213

Code

function forum_update_10101(&$sandbox = NULL) : PluralTranslatableMarkup {
    $query = \Drupal::database()->select('forum_index', 'fi')
        ->fields('fi', [
        'nid',
        'tid',
    ])
        ->groupBy('nid')
        ->groupBy('tid');
    $query->addExpression('count(*)', 'count');
    $query->having('count(*) > 1');
    $results = $query->execute();
    $nids_to_rebuild = [];
    foreach ($results as $row) {
        \Drupal::database()->delete('forum_index')
            ->condition('tid', $row->tid)
            ->condition('nid', $row->nid)
            ->execute();
        $nids_to_rebuild[] = $row->nid;
    }
    \Drupal::state()->set('forum_update_10101_nids', $nids_to_rebuild);
    return new PluralTranslatableMarkup(count($nids_to_rebuild), 'Removed 1 duplicate entry from forum_index', 'Removed @count duplicate entries from forum_index');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.