You are here

function acquia_search_search_api_index_load in Acquia Search 3.x

Same name and namespace in other branches
  1. 2.x acquia_search.module \acquia_search_search_api_index_load()

Implements hook_search_api_index_load().

This takes care of marking indexes as read-only mode under the right conditions (

See also

acquia_search_search_api_server_load()).

File

./acquia_search.module, line 72
Integration between Drupal and Acquia's hosted Solr search service.

Code

function acquia_search_search_api_index_load($entities) {

  // Loop through the Index entities.

  /** @var \Drupal\search_api\Entity\Index $index */
  foreach ($entities as &$index) {

    // Check for server-less indexes.
    // @see https://www.drupal.org/project/acquia_connector/issues/2956737
    $serverId = $index
      ->getServerId();
    if (!isset($serverId) || $serverId == '') {
      continue;
    }
    $server = Server::load($serverId);
    if (!$server) {
      continue;
    }
    if (!Runtime::isAcquiaServer($server)) {
      continue;
    }

    // Reset the overridden_by_acquia_search option.
    $options = $index
      ->getOptions();
    if (!empty($options['overridden_by_acquia_search'])) {
      unset($options['overridden_by_acquia_search']);
      $index
        ->setOptions($options);
    }
    if (Runtime::shouldEnforceReadOnlyMode()) {

      // Set this index to read-only mode.
      $index
        ->set('read_only', TRUE);

      // Flag this index as having been altered by this module.
      $index
        ->setOption('overridden_by_acquia_search', SearchApiSolrAcquiaConnector::READ_ONLY);
    }
  }
}