Issue #2547865 by mrf, StryKaizer: Better file name for config.tar.gz export
parent
f8fbcbea8f
commit
3a0a28e663
|
@ -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 @@ class ConfigExportUITest extends WebTestBase {
|
|||
$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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue