You are here

function search_api_acquia_search_api_index_load in Acquia Search for Search API 7.2

Implements hook_search_api_index_load()

This takes care of enforcing read-only mode, because that happens at the Search API index (and not at the server).

Parameters

array $indexes: Array of Search API index entities.

File

./search_api_acquia.module, line 155
Provides integration between your Drupal site and Acquia's hosted search service via the Search API Solr module.

Code

function search_api_acquia_search_api_index_load($indexes) {
  global $conf;
  $auto_switch_disabled = variable_get('acquia_search_disable_auto_switch', 0);
  $read_only_switch_disabled = variable_get('acquia_search_disable_auto_read_only', 0);
  $subscription = acquia_agent_settings('acquia_subscription_data');
  $sub_active = !empty($subscription['active']);
  if (!$auto_switch_disabled && !$read_only_switch_disabled && $sub_active && !module_exists('acquia_search_multi_subs')) {
    foreach ($indexes as &$index) {
      if (empty($index->server)) {

        // This covers circumstances where the Acquia Search service hasn't
        // been completely set up. Preventing an empty server machine name
        // from loading prevents array_flip errors in entity_load that are
        // otherwise hard to debug.
        continue;
      }
      $server = search_api_server_load($index->server);
      if (!method_exists($server, 'getAcquiaSearchApiVersion') || !search_api_acquia_get_core_service($server
        ->getAcquiaSearchApiVersion())
        ->isPreferredCoreAvailable()) {
        continue;
      }
      if ($server && $server->class == 'acquia_search_service') {
        $index->read_only = '1';
        $conf['search_api_acquia_overrides'][$index->server]['overridden_by_acquia_search'] = SEARCH_API_ACQUIA_AUTO_OVERRIDE_READ_ONLY;
      }
    }
  }
}