You are here

function search_api_db_update_8103 in Search API 8

Converts the old "partial_matches" option to the new "matching" option.

File

modules/search_api_db/search_api_db.install, line 83
Install, update and uninstall functions for the Database Search module.

Code

function search_api_db_update_8103() {

  // @see https://www.drupal.org/node/2971033
  $config_factory = \Drupal::configFactory();
  $count = 0;
  foreach ($config_factory
    ->listAll('search_api.server.') as $server_id) {
    $server = $config_factory
      ->getEditable($server_id);
    if ($server
      ->get('backend') !== 'search_api_db') {
      continue;
    }
    ++$count;
    $config = $server
      ->get('backend_config') ?: [];
    $config['matching'] = empty($config['partial_matches']) ? 'words' : 'partial';
    unset($config['partial_matches']);
    $server
      ->set('backend_config', $config);

    // Mark the resulting configuration as trusted data. This avoids issues
    // with future schema changes.
    $server
      ->save(TRUE);
  }
  if ($count) {
    return \Drupal::translation()
      ->formatPlural($count, 'Updated 1 server.', 'Updated @count servers.');
  }
  return NULL;
}