You are here

function search_api_update_7104 in Search API 7

Change {search_api_item}.index_id back to the index' numeric ID.

File

./search_api.install, line 657
Install, update and uninstall functions for the Search API module.

Code

function search_api_update_7104() {
  $select = db_select('search_api_index', 'i')
    ->fields('i');
  foreach ($select
    ->execute() as $index) {

    // We explicitly forbid numeric machine names, therefore we don't have to
    // worry about conflicts here.
    db_update('search_api_item')
      ->fields(array(
      'index_id' => $index->id,
    ))
      ->condition('index_id', $index->machine_name)
      ->execute();
  }

  // Update primary key and index.
  db_drop_index('search_api_item', 'indexing');
  db_drop_primary_key('search_api_item');
  $spec = array(
    'description' => 'The {search_api_index}.id this item belongs to.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
  );
  $keys_new = array(
    'indexes' => array(
      'indexing' => array(
        'index_id',
        'changed',
      ),
    ),
    'primary key' => array(
      'item_id',
      'index_id',
    ),
  );
  db_change_field('search_api_item', 'index_id', 'index_id', $spec, $keys_new);
}