You are here

function acquia_search_acquia_subscription_status in Acquia Connector 8

Same name and namespace in other branches
  1. 7 acquia_search/acquia_search.module \acquia_search_acquia_subscription_status()
  2. 7.2 acquia_search/acquia_search.module \acquia_search_acquia_subscription_status()

Implements hook_acquia_subscription_status().

File

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

Code

function acquia_search_acquia_subscription_status($subscription = FALSE) {
  if (!empty($subscription['active'])) {

    // Refresh the salt with the subscription data returned by the heartbeat
    // since it can change periodically.
    $salt = \Drupal::config('acquia_search.settings')
      ->get('derived_key_salt');
    if (isset($subscription['derived_key_salt']) && $salt != $subscription['derived_key_salt']) {
      \Drupal::configFactory()
        ->getEditable('acquia_search.settings')
        ->set('derived_key_salt', $subscription['derived_key_salt'])
        ->save();
    }

    // Enable search.

    /** @var \Drupal\search_api\Entity\Server $server */
    if ($server = Server::load('acquia_search_server')) {
      $server
        ->set('status', TRUE);
      $server
        ->save();
    }

    /** @var \Drupal\search_api\Entity\Index $index */
    if ($index = Index::load('acquia_search_index')) {
      $index
        ->set('status', TRUE);
      $index
        ->save();
    }
  }
  elseif (is_int($subscription)) {

    // @todo: Maybe we don't want to switch off search/index because there could
    // be an override in place. But perhaps we need to log it or show a message.
    switch ($subscription) {
      case Subscription::NOT_FOUND:
      case Subscription::EXPIRED:

        // Disable search.

        /** @var \Drupal\search_api\Entity\Server $server */
        if ($server = Server::load('acquia_search_server')) {
          $server
            ->set('status', FALSE);
          $server
            ->save();
        }

        /** @var \Drupal\search_api\Entity\Index $index */
        if ($index = Index::load('acquia_search_index')) {
          $index
            ->set('status', FALSE);
          $index
            ->save();
        }
        break;
    }
  }
}