diff --git a/core/modules/config/config.module b/core/modules/config/config.module index f58dff9..5348024 100644 --- a/core/modules/config/config.module +++ b/core/modules/config/config.module @@ -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, ); } } diff --git a/core/modules/config/src/Tests/ConfigExportUITest.php b/core/modules/config/src/Tests/ConfigExportUITest.php index 1a679de..3c672da 100644 --- a/core/modules/config/src/Tests/ConfigExportUITest.php +++ b/core/modules/config/src/Tests/ConfigExportUITest.php @@ -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();