You are here

function search_api_db_update_7103 in Search API Database Search 7

Change date fields from int to big int.

The purpose is to support historical dates.

File

./search_api_db.install, line 90

Code

function search_api_db_update_7103() {
  $server_options = db_select('search_api_server', 's')
    ->fields('s', array(
    'options',
  ))
    ->condition('class', 'search_api_db_service')
    ->execute()
    ->fetchCol();
  $spec = array(
    'type' => 'int',
    'size' => 'big',
  );
  foreach ($server_options as $options) {
    $options = unserialize($options);
    if (!empty($options['indexes'])) {
      list($key, $target) = explode(':', $options['database'], 2);
      $connection = Database::getConnection($target, $key);
      foreach ($options['indexes'] as $fields) {
        foreach ($fields as $field) {
          if ($field['type'] == 'date') {
            $column = !empty($field['column']) ? $field['column'] : 'value';
            $connection
              ->schema()
              ->changeField($field['table'], $column, $column, $spec);
          }
        }
      }
    }
  }
}