You are here

public function SolrConfigSetController::streamConfigZip in Search API Solr 8.3

Same name and namespace in other branches
  1. 4.x src/Controller/SolrConfigSetController.php \Drupal\search_api_solr\Controller\SolrConfigSetController::streamConfigZip()

Streams a zip archive containing a complete Solr configuration.

Parameters

\Drupal\search_api\ServerInterface $search_api_server: The Search API server entity.

Return value

\Symfony\Component\HttpFoundation\Response The HTTP response object.

Throws

\Drupal\search_api\SearchApiException

1 string reference to 'SolrConfigSetController::streamConfigZip'
search_api_solr.routing.yml in ./search_api_solr.routing.yml
search_api_solr.routing.yml

File

src/Controller/SolrConfigSetController.php, line 351

Class

SolrConfigSetController
Provides different listings of SolrFieldType.

Namespace

Drupal\search_api_solr\Controller

Code

public function streamConfigZip(ServerInterface $search_api_server) : Response {
  $this
    ->setServer($search_api_server);
  try {
    $archive_options = new Archive();
    $archive_options
      ->setSendHttpHeaders(TRUE);
    @ob_clean();

    // If you are using nginx as a webserver, it will try to buffer the
    // response. We have to disable this with a custom header.
    // @see https://github.com/maennchen/ZipStream-PHP/wiki/nginx
    header('X-Accel-Buffering: no');
    $zip = $this
      ->getConfigZip($archive_options);
    $zip
      ->finish();
    @ob_end_flush();
    exit;
  } catch (SearchApiSolrConflictingEntitiesException $e) {
    $this
      ->messenger()
      ->addError($this
      ->t('Some enabled parts of the configuration conflict with others: @conflicts', [
      '@conflicts' => new FormattableMarkup($e, []),
    ]));
  } catch (\Exception $e) {
    watchdog_exception('search_api', $e);
    $this
      ->messenger()
      ->addError($this
      ->t('An error occured during the creation of the config.zip. Look at the logs for details.'));
  }
  return new RedirectResponse($search_api_server
    ->toUrl('canonical')
    ->toString());
}