Commit 7b3bf57b authored by alexpott's avatar alexpott

Issue #2032711 by juampy: Catch exceptions thrown by ArchiveTar when importing configuration.

parent b416a377
......@@ -39,16 +39,21 @@ public function validateForm(array &$form, array &$form_state) {
public function submitForm(array &$form, array &$form_state) {
if ($path = $form_state['values']['import_tarball']) {
\Drupal::service('config.storage.staging')->deleteAll();
try {
$archiver = new ArchiveTar($path, 'gz');
$files = array();
foreach ($archiver->listContent() as $file) {
$files[] = $file['filename'];
}
$archiver->extractList($files, config_get_config_directory(CONFIG_STAGING_DIRECTORY));
drupal_unlink($path);
drupal_set_message('Your configuration files were successfully uploaded, ready for import.');
$form_state['redirect'] = 'admin/config/development/sync';
}
catch (\Exception $e) {
form_set_error('import_tarball', t('Could not extract the contents of the tar file. The error message is <em>@message</em>', array('@message' => $e->getMessage())));
}
drupal_unlink($path);
}
}
}
<?php
/**
* @file
* Definition of Drupal\config\Tests\ConfigImportUploadTest.
*/
namespace Drupal\config\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests importing configuration from an uploaded file.
*/
class ConfigImportUploadTest extends WebTestBase {
public static $modules = array('config');
public static function getInfo() {
return array(
'name' => 'Import uploaded config',
'description' => 'Tests importing configuration from an uploaded file.',
'group' => 'Configuration'
);
}
function setUp() {
parent::setUp();
$this->web_user = $this->drupalCreateUser(array('import configuration'));
$this->drupalLogin($this->web_user);
}
/**
* Tests importing configuration.
*/
function testImport() {
// Verify access to the config upload form.
$this->drupalGet('admin/config/development/import');
$this->assertResponse(200);
// Attempt to upload a non-tar file.
$text_file = current($this->drupalGetTestFiles('text'));
$edit = array('files[import_tarball]' => drupal_realpath($text_file->uri));
$this->drupalPost('admin/config/development/import', $edit, t('Upload'));
$this->assertText(t('Could not extract the contents of the tar file'));
}
}
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