Commit 3a0a28e6 authored by alexpott's avatar alexpott
Browse files

Issue #2547865 by mrf, StryKaizer: Better file name for config.tar.gz export

parent f8fbcbea
......@@ -65,8 +65,14 @@ function config_file_download($uri) {
$scheme = file_uri_scheme($uri);
$target = file_uri_target($uri);
if ($scheme == 'temporary' && $target == 'config.tar.gz') {
$request = \Drupal::request();
$date = DateTime::createFromFormat('U', $request->server->get('REQUEST_TIME'));
$date_string = $date->format('Y-m-d-H-i');
$hostname = str_replace('.', '-', $request->getHttpHost());
$filename = 'config' . '-' . $hostname . '-' . $date_string. '.tar.gz';
$disposition = 'attachment; filename="' . $filename . '"';
return array(
'Content-disposition' => 'attachment; filename="config.tar.gz"',
'Content-disposition' => $disposition,
);
}
}
......@@ -46,6 +46,13 @@ function testExport() {
$this->drupalPostForm('admin/config/development/configuration/full/export', array(), t('Export'));
$this->assertResponse(200, 'User can access the download callback.');
// Test if header contains file name with hostname and timestamp.
$request = \Drupal::request();
$hostname = str_replace('.', '-', $request->getHttpHost());
$header_content_disposition = $this->drupalGetHeader('content-disposition');
$header_match = (boolean) preg_match('/attachment; filename="config-' . preg_quote($hostname) . '-\d{4}-\d{2}-\d{2}-\d{2}-\d{2}\.tar\.gz"/', $header_content_disposition);
$this->assertTrue($header_match, "Header with filename matches the expected format.");
// Get the archived binary file provided to user for download.
$archive_data = $this->getRawContent();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment