You are here

function acquia_search_search_api_index_load in Acquia Connector 8

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/acquia_search.module, line 250
Integration between Acquia Drupal and Acquia's hosted solr search service.

Code

function acquia_search_search_api_index_load($entities) {

  // Loop through the Index entities.
  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;
    }

    // Checking for serverless indexes.
    $serverId = $index
      ->getServerId();
    if (!$serverId) {
      continue;
    }

    // Check for non-existent servers.

    /** @var \Drupal\search_api\Entity\Index $index */
    $server = Server::load($serverId);
    if (!$server) {
      continue;
    }
    if (!acquia_search_is_acquia_server($server
      ->getBackendConfig())) {
      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 (acquia_search_should_set_read_only_mode()) {

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

      // Flag this index as having been altered by this module.
      \Drupal::state()
        ->set('acquia_search_index.' . $index
        ->id() . '.overridden_by_acquia_search', ACQUIA_SEARCH_AUTO_OVERRIDE_READ_ONLY);
    }
  }
}