You are here

public static function AcquiaSearchSolrEnvironment::override in Acquia Connector 7.3

Overrides search environments configuration.

Parameters

array $environments: Environments list.

AcquiaSearchSolrPreferredIndex $preferredIndexService: Preferred index service.

File

acquia_search/includes/AcquiaSearchSolrEnvironment.php, line 28

Class

AcquiaSearchSolrEnvironment
Class AcquiaSearchSolrEnvironment.

Code

public static function override(array $environments, AcquiaSearchSolrPreferredIndex $preferredIndexService) {
  global $conf;
  $possible_indexes = $preferredIndexService
    ->getListOfPossibleIndexes();
  $available_indexes = $preferredIndexService
    ->getAvailableIndexesIds();
  $overrode = FALSE;
  foreach ($environments as $acquia_env_id => $environment) {

    // Override Acquia search environments only.
    // Also skip if the Acquia search environment has already been overridden.
    if (!self::isConnected($environment) || self::isOverridden($conf, $acquia_env_id)) {
      continue;
    }

    // Just for better readability.
    $environment_config =& $conf['apachesolr_environments'][$acquia_env_id];
    $environment_config['acquia_search_solr_possible_indexes'] = $possible_indexes;
    $environment_config['acquia_search_solr_available_indexes'] = $available_indexes;
    $environment_config = self::overrideUrl($preferredIndexService, $environment_config);
    if ($preferredIndexService
      ->isPreferredIndexAvailable()) {
      $environment_config['overridden_by_acquia_search_solr'] = self::OVERRIDE_AUTO_SET;
      $overrode = TRUE;
      drupal_static_reset('apachesolr_load_all_environments');
      continue;
    }

    // Switch the search into read-only mode.
    if (variable_get('acquia_search_solr_forced_read_only', FALSE)) {
      $environment_config['overridden_by_acquia_search_solr'] = self::READ_ONLY;
      $environment_config['conf'] = [
        'apachesolr_read_only' => APACHESOLR_READ_ONLY,
      ];
      $overrode = TRUE;
      drupal_static_reset('apachesolr_load_all_environments');
    }
  }
  if ($overrode) {

    // If an override was applied, then clear the corresponding cache item.
    cache_clear_all('apachesolr:environments', 'cache_apachesolr');
  }
}