You are here

function suggestion_update_8201 in Autocomplete Search Suggestions 8.2

Add language column.

File

./suggestion.install, line 80
Contains suggestion.install.

Code

function suggestion_update_8201() {
  module_load_include('inc', 'suggestion', 'suggestion.install');
  $schema = Database::getConnection()
    ->schema();
  $spec = suggestion_install_update_8201_spec();
  if (!$schema
    ->fieldExists('suggestion', 'langcode')) {
    $schema
      ->addField('suggestion', 'langcode', $spec['fields']['langcode']);
  }

  // Add new indexes.
  if (!$schema
    ->indexExists('suggestion', 'langcode')) {
    $schema
      ->addIndex('suggestion', 'langcode', [
      'langcode',
    ], $spec);
  }
  if (!$schema
    ->indexExists('suggestion', 'src')) {
    $schema
      ->addIndex('suggestion', 'src', [
      'src',
    ], $spec);
  }
  if (!$schema
    ->indexExists('suggestion', 'src_lang')) {
    $schema
      ->addIndex('suggestion', 'src_lang', $spec['indexes']['src_lang'], $spec);
  }
  if (!$schema
    ->indexExists('suggestion', 'density_ngram_atom')) {
    $schema
      ->addIndex('suggestion', 'density_ngram_atom', $spec['indexes']['density_ngram_atom'], $spec);
  }
  if (!$schema
    ->indexExists('suggestion', 'atom_src_lang_ngram')) {
    $schema
      ->addIndex('suggestion', 'atom_src_lang_ngram', $spec['indexes']['atom_src_lang_ngram'], $spec);
  }

  // Replace primary index.
  $schema
    ->dropPrimaryKey('suggestion');
  $schema
    ->addPrimaryKey('suggestion', [
    'langcode',
    'ngram',
  ]);

  // Delete superfluous indexes.
  if ($schema
    ->indexExists('suggestion', 'ngram_atom')) {
    $schema
      ->dropIndex('suggestion', 'ngram_atom');
  }
  if ($schema
    ->indexExists('suggestion', 'ngram_atom_qty')) {
    $schema
      ->dropIndex('suggestion', 'ngram_atom_qty');
  }
  if ($schema
    ->indexExists('suggestion', 'ngram_qty')) {
    $schema
      ->dropIndex('suggestion', 'ngram_qty');
  }
  drupal_flush_all_caches();
}