acquia_search-3.0.1/acquia_search.install

acquia_search.install
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Acquia Search Solr module.
 */

use Drupal\acquia_connector\Subscription;
use Drupal\acquia_search\Helper\Messages;
use Drupal\acquia_search\Helper\Runtime;
use Drupal\acquia_search\Plugin\search_api\backend\AcquiaSearchSolrBackend;
use Drupal\Core\Site\Settings;
use Drupal\search_api\Entity\Server;
use Drupal\search_api\ServerInterface;

/**
 * Implements hook_requirements().
 */
function acquia_search_requirements($phase) {
  $requirements = [];

  if ($phase == 'runtime') {
    if (!\Drupal::moduleHandler()->moduleExists('acquia_connector') || !class_exists(Subscription::class)) {
      $requirements['acquia_search_requirements'] = [
        'title' => t('Acquia Search'),
        'value' => t('Requirements Missing: acquia_connector'),
        'severity' => REQUIREMENT_ERROR,
        'description' => ['#markup' => t('Acquia connector 4.x is required for Acquia Search 3.1.0 and above.')],
      ];
      return $requirements;
    }

    // Detect and report deprecated settings.
    $search_settings = Settings::get('acquia_search');
    $deprecated = [];
    if (!empty($search_settings['server_overrides']) && is_array($search_settings['server_overrides'])) {
      foreach ($search_settings['server_overrides'] as $server_id => $override) {
        if (is_string($override)) {
          $deprecated['acquia_search_deprecated_server_overrides'] = t("Setting the core as a string value on settings.php: acquia_search.server_overrides.SERVER_ID setting has been deprecated in acquia_search:3.2.0 to allow read-only and core settings to be read. String support will removed from acquia_search:3.3.0.");
          break;
        }
      }
    }
    if (\Drupal::configFactory()->get('acquia_search.settings')->get('override_search_core') ||
      \Drupal::configFactory()->get('acquia_search_solr.settings')->get('override_search_core') ||
      (isset($search_settings['override_search_core']) && $search_settings['override_search_core'])) {
      $deprecated['acquia_search_deprecated_config'] = t("Acquia Search detected deprecated config settings. Please review README.txt and use the server_overrides setting to override core ids.");
    }
    if (isset($search_settings['read_only'])) {
      $deprecated['acquia_search_deprecated_read_only'] = t("The global settings.php acquia_search.read_only setting has been deprecated in acquia_search:3.2.0 and will be removed from acquia_search:3.3.0. There is no replacement. Set each servers read-only status individually.");
    }
    foreach ($deprecated as $deprecation => $msg) {
      $requirements[$deprecation] = [
        'title' => t('Acquia Search Local Overrides'),
        'value' => 'Local override',
        'description' => $msg,
        'severity' => REQUIREMENT_WARNING,
      ];
    }

    $requirements['acquia_search_ssl'] = [
      'title' => t('Acquia Search Solr'),
      'value' => 'Security',
    ];
    // Check SSL support.
    if (in_array('ssl', stream_get_transports(), TRUE)) {
      $requirements['acquia_search_ssl']['severity'] = REQUIREMENT_OK;
      $requirements['acquia_search_ssl']['description'] = t('The Acquia Search module is using SSL to protect the privacy of your content.');
    }
    else {
      $requirements['acquia_search_ssl']['severity'] = REQUIREMENT_WARNING;
      $requirements['acquia_search_ssl']['description'] = t('In order to protect the privacy of your content with the Acquia Search module you must have SSL support enabled in PHP on your host.');
    }

    /** @var \Drupal\search_api\ServerInterface[] $servers */
    $servers = Server::loadMultiple();

    $acquia_servers = array_filter($servers, static function (ServerInterface $server) {
      return Runtime::isAcquiaServer($server);
    });

    // Show available Acquia Search Solr indexes.
    foreach ($acquia_servers as $server_id => $server) {
      $backend = $server->getBackend();
      $requirements['acquia_search_status_' . $server_id] = [
        'title' => t('Acquia Search connection status'),
        'severity' => REQUIREMENT_OK,
        'description' => ['#markup' => Messages::getSearchStatusMessage($server->getBackend())],
      ];
      if ($backend instanceof AcquiaSearchSolrBackend && !$backend->isPreferredCoreAvailable()) {
        $requirements['acquia_search_status_' . $server_id]['severity'] = REQUIREMENT_ERROR;
        $requirements['acquia_search_status_' . $server_id]['description'] = ['#markup' => Messages::getNoPreferredCoreError($backend)];
      }
      if ($backend instanceof AcquiaSearchSolrBackend && !$backend->isPreferredCoreAvailable()) {
        $requirements['acquia_search_status_' . $server_id]['severity'] = REQUIREMENT_WARNING;
        $requirements['acquia_search_status_' . $server_id]['description'] = ['#markup' => Messages::getReadOnlyModeWarning()];
      }
    }
    $settings = \Drupal::config("acquia_search.settings");
    if ($settings->get("read_only")) {
      $requirements['acquia_search_read_only'] = [
        'title' => t('Acquia Search Solr'),
        'value' => t('Read-only warning'),
        'severity' => REQUIREMENT_WARNING,
        'description' => ['#markup' => 'The read-only mode is set in the configuration of the Acquia Search Solr module.'],
      ];
    }
  }

  return $requirements;
}

/**
 * Enable the acquia_connector module.
 */
function acquia_search_update_8310() {
  \Drupal::service('module_installer')->install(['acquia_connector']);
}

/**
 * Enable acquia search defaults for existing sites with the default server.
 */
function acquia_search_update_8320() {
  $default_server = Server::load('acquia_search_server');
  if ($default_server !== NULL && Runtime::isAcquiaServer($default_server)) {
    \Drupal::service('module_installer')->install(['acquia_search_defaults']);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc