function forum_update_10102

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

Add a primary key to forum_index.

File

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

Code

function forum_update_10102(&$sandbox = NULL) {
    $connection = \Drupal::database();
    if ($connection->schema()
        ->tableExists('forum_index')) {
        // Data in this table could have duplicates. The data can be re-constructed
        // from other data in the site. To avoid duplicate key errors we delete any
        // rows that are duplicates and then recreate them in a post-update hook.
        // @see \forum_post_update_recreate_forum_index_rows().
        $connection->schema()
            ->addPrimaryKey('forum_index', [
            'nid',
            'tid',
        ]);
        return \t('Added primary key to the forum_index table.');
    }
    return \t('Index already exists');
}

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