You are here

public function SolrCommandHelper::getServerConfigCommand in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Utility/SolrCommandHelper.php \Drupal\search_api_solr\Utility\SolrCommandHelper::getServerConfigCommand()

Gets the config for a Solr search server.

Parameters

string $server_id: The ID of the server.

string $file_name: The file name of the config zip that should be created.

string $solr_version: The targeted Solr version.

Throws

\Drupal\search_api\SearchApiException

\ZipStream\Exception\FileNotFoundException

\ZipStream\Exception\FileNotReadableException

\ZipStream\Exception\OverflowException

1 call to SolrCommandHelper::getServerConfigCommand()
SolrAdminCommandHelper::uploadConfigset in modules/search_api_solr_admin/src/Utility/SolrAdminCommandHelper.php
Generates and uploads the configset for a Solr search server.

File

src/Utility/SolrCommandHelper.php, line 39

Class

SolrCommandHelper
Provides functionality to be used by CLI tools.

Namespace

Drupal\search_api_solr\Utility

Code

public function getServerConfigCommand($server_id, $file_name = NULL, $solr_version = NULL) {
  $server = $this
    ->getServer($server_id);
  if ($solr_version) {
    $config = $server
      ->getBackendConfig();

    // Temporarily switch the Solr version but don't save!
    $config['connector_config']['solr_version'] = $solr_version;
    $server
      ->setBackendConfig($config);
  }
  $solr_configset_controller = new SolrConfigSetController();
  $solr_configset_controller
    ->setServer($server);
  $archive_options = new Archive();
  $stream = FALSE;
  if ($file_name !== NULL) {

    // If no filename is provided, output stream is standard output.
    $stream = fopen($file_name, 'w+b');
    $archive_options
      ->setOutputStream($stream);
  }
  $zip = $solr_configset_controller
    ->getConfigZip($archive_options);
  $zip
    ->finish();
  if ($stream) {
    fclose($stream);
  }
}