You are here

function search_api_db_update_7101 in Search API Database Search 7

Replace numeric index IDs with machine names in the server options.

File

./search_api_db.install, line 25

Code

function search_api_db_update_7101() {
  $query = db_select('search_api_server', 's');
  $query
    ->addField('s', 'machine_name');
  $query
    ->condition('class', 'search_api_db_service');
  $index_names = db_select('search_api_index', 'i')
    ->fields('i', array(
    'id',
    'machine_name',
  ))
    ->condition('server', clone $query, 'IN')
    ->execute()
    ->fetchAllKeyed();
  $query
    ->addField('s', 'options');
  $servers = $query
    ->execute();
  foreach ($servers
    ->fetchAllKeyed() as $name => $options) {
    $options = unserialize($options);
    if (empty($options['indexes'])) {
      continue;
    }
    $indexes = array();
    foreach ($options['indexes'] as $id => $info) {
      if (isset($index_names[$id])) {
        $indexes[$index_names[$id]] = $info;
      }
    }
    $options['indexes'] = $indexes;
    $options = serialize($options);
    db_update('search_api_server')
      ->fields(array(
      'options' => $options,
    ))
      ->condition('machine_name', $name)
      ->execute();
  }
}