You are here

function _social_search_retrigger_profile in Open Social 8.9

Same name and namespace in other branches
  1. 8.2 modules/social_features/social_search/social_search.module \_social_search_retrigger_profile()
  2. 8.3 modules/social_features/social_search/social_search.module \_social_search_retrigger_profile()
  3. 8.4 modules/social_features/social_search/social_search.module \_social_search_retrigger_profile()
  4. 8.5 modules/social_features/social_search/social_search.module \_social_search_retrigger_profile()
  5. 8.6 modules/social_features/social_search/social_search.module \_social_search_retrigger_profile()
  6. 8.7 modules/social_features/social_search/social_search.module \_social_search_retrigger_profile()
  7. 8.8 modules/social_features/social_search/social_search.module \_social_search_retrigger_profile()
  8. 10.0.x modules/social_features/social_search/social_search.module \_social_search_retrigger_profile()
  9. 10.1.x modules/social_features/social_search/social_search.module \_social_search_retrigger_profile()

Retriggers the profile in the search when a user has ben changed.

Parameters

\Drupal\user\Entity\User $user: The user whose profile we want to retrigger.

1 call to _social_search_retrigger_profile()
social_search_user_update in modules/social_features/social_search/social_search.module
Implements hook_ENTITY_TYPE_update().

File

modules/social_features/social_search/social_search.module, line 233
The Social search module.

Code

function _social_search_retrigger_profile(User $user) {

  // These indices need to be updated.
  $indexes = [
    'social_all',
    'social_users',
  ];
  try {

    /** @var \Drupal\profile\ProfileStorage $profile_storage */
    $profile_storage = \Drupal::entityTypeManager()
      ->getStorage('profile');
  } catch (InvalidPluginDefinitionException $e) {
    return;
  } catch (PluginNotFoundException $e) {
    return;
  }

  /** @var \Drupal\profile\Entity\Profile $profile */
  $profile = $profile_storage
    ->loadByUser($user, 'profile');

  // Must be a profile, otherwise we can leave.
  if (!$profile instanceof Profile) {
    return;
  }

  // Loop over the indexes that need to be updated.
  foreach ($indexes as $index_id) {
    $index = Index::load($index_id);
    if ($index instanceof Index) {

      // Init.
      $profile_ids = [];

      /** @var \Drupal\user\Entity\User $original_user */
      $original_user = $user->original;
      foreach ($profile
        ->getTranslationLanguages() as $langcode => $language) {
        $profile_ids[] = $profile
          ->id() . ':' . $langcode;
      }
      $datasource_id = 'entity:profile';
      if ($user
        ->isBlocked() && $original_user
        ->isActive()) {
        $index
          ->trackItemsDeleted($datasource_id, $profile_ids);
      }
      elseif ($user
        ->isActive() && $original_user
        ->isBlocked()) {
        $filtered_item_ids = ContentEntity::filterValidItemIds($index, $datasource_id, $profile_ids);
        $index
          ->trackItemsInserted($datasource_id, $filtered_item_ids);
      }
      else {
        $index
          ->trackItemsUpdated($datasource_id, $profile_ids);
      }
    }
  }
}