You are here

public function ArchiveDownloaderController::downloadArchive in Content Synchronizer 3.x

Same name and namespace in other branches
  1. 8.2 src/Controller/ArchiveDownloaderController.php \Drupal\content_synchronizer\Controller\ArchiveDownloaderController::downloadArchive()
  2. 8 src/Controller/ArchiveDownloaderController.php \Drupal\content_synchronizer\Controller\ArchiveDownloaderController::downloadArchive()

Download the tmp file.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request.

Return value

\Symfony\Component\HttpFoundation\Response|null The download response.

1 string reference to 'ArchiveDownloaderController::downloadArchive'
content_synchronizer.routing.yml in ./content_synchronizer.routing.yml
content_synchronizer.routing.yml

File

src/Controller/ArchiveDownloaderController.php, line 56

Class

ArchiveDownloaderController
Class ArchiveDownloaderController.

Namespace

Drupal\content_synchronizer\Controller

Code

public function downloadArchive(Request $request) {
  if ($request->query
    ->has(ArchiveDownloader::ARCHIVE_PARAMS)) {
    $fileUri = ExportEntityWriter::getGeneratorDir() . $request->query
      ->get(ArchiveDownloader::ARCHIVE_PARAMS);
    if (file_exists($fileUri)) {
      $response = new Response(file_get_contents($fileUri));
      $disposition = $response->headers
        ->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, basename($fileUri));
      $response->headers
        ->set('Content-Disposition', $disposition);

      // Delete temporary file.
      $repName = substr($fileUri, 0, strrpos($fileUri, '/'));
      $this->fileSystem
        ->deleteRecursive($repName);
      return $response;
    }
  }
  return NULL;
}