You are here

public function ContentController::downloadExport in Content Synchronization 8.2

Same name and namespace in other branches
  1. 8 src/Controller/ContentController.php \Drupal\content_sync\Controller\ContentController::downloadExport()
  2. 3.0.x src/Controller/ContentController.php \Drupal\content_sync\Controller\ContentController::downloadExport()

Downloads a tarball of the site content.

1 string reference to 'ContentController::downloadExport'
content_sync.routing.yml in ./content_sync.routing.yml
content_sync.routing.yml

File

src/Controller/ContentController.php, line 93

Class

ContentController
Returns responses for content module routes.

Namespace

Drupal\content_sync\Controller

Code

public function downloadExport() {

  // NOTE:  Getting - You are not authorized to access this page.

  //$request = new Request(['file' => 'content.tar.gz']);

  //return $this->fileDownloadController->download($request, 'temporary');
  $filename = 'content.tar.gz';
  $file_path = $this->fileSystem
    ->getTempDirectory() . '/' . $filename;
  if (file_exists($file_path)) {
    unset($_SESSION['content_tar_download_file']);
    $mime = \Drupal::service('file.mime_type.guesser')
      ->guess($file_path);
    $headers = array(
      'Content-Type' => $mime . '; name="' . Unicode::mimeHeaderEncode(basename($file_path)) . '"',
      'Content-Length' => filesize($file_path),
      'Content-Disposition' => 'attachment; filename="' . Unicode::mimeHeaderEncode($filename) . '"',
      'Cache-Control' => 'private',
    );
    return new BinaryFileResponse($file_path, 200, $headers);
  }
  return -1;
}