You are here

protected function ConfigEventsSubscriber::invalidateSearchIndices in Open Social 8.7

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber::invalidateSearchIndices()
  2. 8.8 modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber::invalidateSearchIndices()
  3. 10.3.x modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber::invalidateSearchIndices()
  4. 10.0.x modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber::invalidateSearchIndices()
  5. 10.1.x modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber::invalidateSearchIndices()
  6. 10.2.x modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php \Drupal\social_profile_privacy\EventSubscriber\ConfigEventsSubscriber::invalidateSearchIndices()

Invalidates the search indices for every index that uses profile data.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\search_api\SearchApiException

1 call to ConfigEventsSubscriber::invalidateSearchIndices()
ConfigEventsSubscriber::configSave in modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php
React to a config object being saved.

File

modules/social_features/social_profile/modules/social_profile_privacy/src/EventSubscriber/ConfigEventsSubscriber.php, line 101

Class

ConfigEventsSubscriber
Class ConfigEventSubscriber.

Namespace

Drupal\social_profile_privacy\EventSubscriber

Code

protected function invalidateSearchIndices() : void {

  // If the search api module is not installed we have nothing to do.
  if (!$this->moduleHandler
    ->moduleExists('search_api')) {
    return;
  }

  // We load all indexes, we assume there will never be hundreds of search
  // indexes which would create its own problems for a site.
  $indexes = $this->entityTypeManager
    ->getStorage('search_api_index')
    ->loadMultiple();

  /** @var \Drupal\search_api\IndexInterface $index */
  foreach ($indexes as $index) {

    // Check if the search index has profile entities as data source.
    if ($index
      ->isValidDatasource('entity:profile')) {

      // Mark any indexed items based on profile entities as having changed so
      // they are re-indexed.
      $index
        ->getTrackerInstance()
        ->trackAllItemsUpdated('entity:profile');
    }
  }
}