You are here

function search_api_update_8103 in Search API 8

Switches from the old "Node status" to the new "Entity status" processor.

File

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

Code

function search_api_update_8103() {

  // This update function updates search indexes for the change from
  // https://www.drupal.org/node/2491175.
  $config_factory = \Drupal::configFactory();
  foreach ($config_factory
    ->listAll('search_api.index.') as $index_id) {
    $index = $config_factory
      ->getEditable($index_id);
    $processors = $index
      ->get('processor_settings');
    if (isset($processors['node_status'])) {
      $processors['entity_status'] = $processors['node_status'];
      unset($processors['node_status']);
      $index
        ->set('processor_settings', $processors);

      // Mark the resulting configuration as trusted data. This avoids issues
      // with future schema changes.
      $index
        ->save(TRUE);
    }
  }

  // Clear the processor plugin cache so that if anything else indirectly tries
  // to update Search API-related configuration, the plugin helper gets the most
  // up-to-date plugin definitions.
  \Drupal::getContainer()
    ->get('plugin.manager.search_api.processor')
    ->clearCachedDefinitions();
  return t('Switched from old "Node status" to new "Entity status" processor.');
}