You are here

private function SearchApiSolrAcquiaMultiSubsBackend::getEnvironmentCore in Acquia Search Multiple Indexes 8

1 call to SearchApiSolrAcquiaMultiSubsBackend::getEnvironmentCore()
SearchApiSolrAcquiaMultiSubsBackend::__construct in src/Plugin/search_api/backend/SearchApiSolrAcquiaMultiSubsBackend.php

File

src/Plugin/search_api/backend/SearchApiSolrAcquiaMultiSubsBackend.php, line 323

Class

SearchApiSolrAcquiaMultiSubsBackend
Plugin annotation @SearchApiBackend( id = "search_api_solr_acquia_multi_subs", label = @Translation("Acquia Solr Multi Sub"), description = @Translation("Index items using a specific Acquia Apache Solr search server.") )

Namespace

Drupal\acquia_search_multi_subs\Plugin\search_api\backend

Code

private function getEnvironmentCore() {
  $ah_site_environment = isset($_ENV['AH_SITE_ENVIRONMENT']) ? $_ENV['AH_SITE_ENVIRONMENT'] : '';
  $ah_site_name = isset($_ENV['AH_SITE_NAME']) ? $_ENV['AH_SITE_NAME'] : '';
  $ah_site_group = isset($_ENV['AH_SITE_GROUP']) ? $_ENV['AH_SITE_GROUP'] : '';
  $ah_region = isset($_ENV['AH_CURRENT_REGION']) ? $_ENV['AH_CURRENT_REGION'] : '';
  $ah_db_name = '';
  if ($ah_site_environment && $ah_site_name && $ah_site_group) {
    $tmp = \Drupal\Core\Database\Database::getConnection()
      ->getConnectionOptions();
    $ah_db_name = $tmp['database'];
  }
  $conf_path = \Drupal::service('site.path');
  $sites_foldername = substr($conf_path, strrpos($conf_path, '/') + 1);
  $acquia_identifier = \Drupal::config('acquia_connector.settings')
    ->get('identifier');
  $subscription_expected_search_cores = $this
    ->getExpectedSearchCores($acquia_identifier, $ah_site_environment, $ah_site_name, $ah_site_group, $sites_foldername, $ah_db_name);

  // Retrieve the list of search cores availablle.
  $subscription = \Drupal::config('acquia_connector.settings')
    ->get('subscription_data');
  $available_search_cores = $subscription['heartbeat_data']['search_cores'];
  $match_found = FALSE;
  foreach ($subscription_expected_search_cores as $expected_core_name) {

    // This allows us to break from the 2-level deep foreach.
    if ($match_found) {
      break;
    }

    // Loop over all the available search cores.
    foreach ($available_search_cores as $available_search_core) {
      if (strtolower($available_search_core['core_id']) == strtolower($expected_core_name)) {
        $core = $available_search_core['core_id'];
        $match_found = TRUE;
        break;
      }
    }
  }
  return $core;
}