You are here

function search_api_update_7106 in Search API 7

Update the settings for the "Aggregated fields" data alteration.

File

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

Code

function search_api_update_7106() {
  $rows = db_select('search_api_index', 'i')
    ->fields('i')
    ->execute()
    ->fetchAll();
  foreach ($rows as $row) {
    $opt = unserialize($row->options);
    $callbacks =& $opt['data_alter_callbacks'];
    if (isset($callbacks['search_api_alter_add_fulltext'])) {
      $callbacks['search_api_alter_add_aggregation'] = $callbacks['search_api_alter_add_fulltext'];
      unset($callbacks['search_api_alter_add_fulltext']);
      if (!empty($callbacks['search_api_alter_add_aggregation']['settings']['fields'])) {
        foreach ($callbacks['search_api_alter_add_aggregation']['settings']['fields'] as &$info) {
          if (!isset($info['type'])) {
            $info['type'] = 'fulltext';
          }
        }
      }
    }
    $opt = serialize($opt);
    if ($opt != $row->options) {

      // Mark the entity as overridden, in case it has been defined in code
      // only.
      $row->status |= 0x1;
      db_update('search_api_index')
        ->fields(array(
        'options' => $opt,
        'status' => $row->status,
      ))
        ->condition('id', $row->id)
        ->execute();
    }
  }
}