You are here

public function PreferredSearchCoreService::getListOfPossibleCores in Acquia Search 2.x

Returns a list of all possible search core IDs.

The core IDs are generated based on the current site configuration.

Return value

array E.g. [ 'WXYZ-12345', 'WXYZ-12345.dev.mysitedev_folder1', 'WXYZ-12345.dev.mysitedev_db', ]

1 call to PreferredSearchCoreService::getListOfPossibleCores()
PreferredSearchCoreService::getPreferredCore in src/PreferredSearchCoreService.php
Returns the preferred core from the list of available cores.

File

src/PreferredSearchCoreService.php, line 228

Class

PreferredSearchCoreService
Serivce to check for preferred search core.

Namespace

Drupal\acquia_search

Code

public function getListOfPossibleCores() {
  $possible_core_ids = [];

  // The Acquia Search Solr module tries to use this core before any auto
  // detected core in case if it's set in the site configuration.
  if ($default_search_core = \Drupal::config('acquia_search.settings')
    ->get('default_search_core')) {
    $possible_core_ids[] = $default_search_core;
  }

  // In index naming, we only accept alphanumeric chars.
  $sites_foldername = preg_replace('/[^a-zA-Z0-9]+/', '', $this->sitesFolderName);
  $ah_env = preg_replace('/[^a-zA-Z0-9]+/', '', $this->ahEnv);
  $context = [
    'ah_env' => $ah_env,
    'ah_db_role' => $this->ahDbName,
    'identifier' => $this->acquiaIdentifier,
    'sites_foldername' => $sites_foldername,
  ];
  if ($ah_env) {

    // When there is an Acquia DB name defined, priority is to pick
    // WXYZ-12345.[env].[db_name], then WXYZ-12345.[env].[site_foldername].
    // If we're sure this is prod, then 3rd option is WXYZ-12345.
    // @todo Support for [id]_[env][sitename] cores?
    if ($this->ahDbName) {
      $possible_core_ids[] = $this->acquiaIdentifier . '.' . $ah_env . '.' . $this->ahDbName;
    }
    $possible_core_ids[] = $this->acquiaIdentifier . '.' . $ah_env . '.' . $sites_foldername;
  }

  // For production-only, we allow auto-connecting to the suffix-less core
  // as the fallback.
  if (!empty($_SERVER['AH_PRODUCTION']) || !empty($_ENV['AH_PRODUCTION'])) {
    $possible_core_ids[] = $this->acquiaIdentifier;
  }

  // Let other modules alter the list possible cores.
  \Drupal::moduleHandler()
    ->alter('acquia_search_get_list_of_possible_cores', $possible_core_ids, $context);
  return $possible_core_ids;
}