You are here

public function SearchApiSolrBackend::viewSettings in Search API Solr 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::viewSettings()
  2. 8 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::viewSettings()
  3. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::viewSettings()

Throws

\Drupal\Component\Plugin\Exception\PluginException

Overrides BackendPluginBase::viewSettings

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 507

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function viewSettings() {

  /** @var \Drupal\search_api_solr\Plugin\SolrConnector\StandardSolrCloudConnector $connector */
  $connector = $this
    ->getSolrConnector();
  $cloud = $connector instanceof SolrCloudConnectorInterface;
  $info[] = [
    'label' => $this
      ->t('Solr connector plugin'),
    'info' => $connector
      ->label(),
  ];
  $info[] = [
    'label' => $this
      ->t('Solr server URI'),
    'info' => $connector
      ->getServerLink(),
  ];
  if ($cloud) {
    $info[] = [
      'label' => $this
        ->t('Solr collection URI'),
      'info' => $connector
        ->getCollectionLink(),
    ];
  }
  else {
    $info[] = [
      'label' => $this
        ->t('Solr core URI'),
      'info' => $connector
        ->getCoreLink(),
    ];
  }

  // Add connector-specific information.
  $info = array_merge($info, $connector
    ->viewSettings());
  if ($this->server
    ->status()) {

    // If the server is enabled, check whether Solr can be reached.
    $ping_server = $connector
      ->pingServer();
    if ($ping_server) {
      $msg = $this
        ->t('The Solr server could be reached.');
    }
    else {
      $msg = $this
        ->t('The Solr server could not be reached or is protected by your service provider.');
    }
    $info[] = [
      'label' => $this
        ->t('Server Connection'),
      'info' => $msg,
      'status' => $ping_server ? 'ok' : 'error',
    ];
    $ping = $connector
      ->pingCore();
    if ($ping) {
      $msg = $this
        ->t('The Solr @core could be accessed (latency: @millisecs ms).', [
        '@core' => $cloud ? 'collection' : 'core',
        '@millisecs' => $ping * 1000,
      ]);
    }
    else {
      $msg = $this
        ->t('The Solr @core could not be accessed. Further data is therefore unavailable.', [
        '@core' => $cloud ? 'collection' : 'core',
      ]);
    }
    $info[] = [
      'label' => $cloud ? $this
        ->t('Collection Connection') : $this
        ->t('Core Connection'),
      'info' => $msg,
      'status' => $ping ? 'ok' : 'error',
    ];
    $version = $connector
      ->getSolrVersion();
    $info[] = [
      'label' => $this
        ->t('Configured Solr Version'),
      'info' => $version,
      'status' => version_compare($version, '0.0.0', '>') ? 'ok' : 'error',
    ];
    if ($ping_server || $ping) {
      $info[] = [
        'label' => $this
          ->t('Detected Solr Version'),
        'info' => $connector
          ->getSolrVersion(TRUE),
        'status' => 'ok',
      ];
      try {

        // If Solr can be reached, provide more information. This isn't done
        // often (only when an admin views the server details), so we clear
        // the cache to get the current data.
        $data = $connector
          ->getLuke();
        if (isset($data['index']['numDocs'])) {

          // Collect the stats.
          $stats_summary = $connector
            ->getStatsSummary();
          $pending_msg = $stats_summary['@pending_docs'] ? $this
            ->t('(@pending_docs sent but not yet processed)', $stats_summary) : '';
          $index_msg = $stats_summary['@index_size'] ? $this
            ->t('(@index_size on disk)', $stats_summary) : '';
          $indexed_message = $this
            ->t('@num items @pending @index_msg', [
            '@num' => $data['index']['numDocs'],
            '@pending' => $pending_msg,
            '@index_msg' => $index_msg,
          ]);
          $info[] = [
            'label' => $this
              ->t('Indexed'),
            'info' => $indexed_message,
          ];
          if (!empty($stats_summary['@deletes_total'])) {
            $info[] = [
              'label' => $this
                ->t('Pending Deletions'),
              'info' => $stats_summary['@deletes_total'],
            ];
          }
          $info[] = [
            'label' => $this
              ->t('Delay'),
            'info' => $this
              ->t('@autocommit_time before updates are processed.', $stats_summary),
          ];
          $status = 'ok';
          if (empty($this->configuration['skip_schema_check'])) {
            if (substr($stats_summary['@schema_version'], 0, 10) == 'search-api') {
              \Drupal::messenger()
                ->addError($this
                ->t('Your schema.xml version is too old. Please replace all configuration files with the ones packaged with this module and re-index you data.'));
              $status = 'error';
            }
            elseif (!preg_match('/drupal-[' . SEARCH_API_SOLR_MIN_SCHEMA_VERSION . '-9]\\./', $stats_summary['@schema_version'])) {
              $variables[':url'] = Url::fromUri('internal:/' . drupal_get_path('module', 'search_api_solr') . '/INSTALL.md')
                ->toString();
              \Drupal::messenger()
                ->addError($this
                ->t('You are using an incompatible schema.xml configuration file. Please follow the instructions in the <a href=":url">INSTALL.md</a> file for setting up Solr.', $variables));
              $status = 'error';
            }
          }
          $info[] = [
            'label' => $this
              ->t('Schema'),
            'info' => $stats_summary['@schema_version'],
            'status' => $status,
          ];
          if (!empty($stats_summary['@collection_name'])) {
            $info[] = [
              'label' => $this
                ->t('Solr Collection Name'),
              'info' => $stats_summary['@collection_name'],
            ];
          }
          elseif (!empty($stats_summary['@core_name'])) {
            $info[] = [
              'label' => $this
                ->t('Solr Core Name'),
              'info' => $stats_summary['@core_name'],
            ];
          }
        }
      } catch (SearchApiException $e) {
        $info[] = [
          'label' => $this
            ->t('Additional information'),
          'info' => $this
            ->t('An error occurred while trying to retrieve additional information from the Solr server: %msg', [
            '%msg' => $e
              ->getMessage(),
          ]),
          'status' => 'error',
        ];
      }
    }
  }
  $info[] = [
    'label' => $this
      ->t('Targeted content domain'),
    'info' => $this
      ->getDomain(),
  ];
  return $info;
}