Skip to content
Snippets Groups Projects
Commit 5132930c authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2579399 by phenaproxima, mikeryan, neclimdul: db-tools.php import does not work

parent 0eed649b
No related branches found
No related tags found
No related merge requests found
...@@ -58,6 +58,8 @@ protected function execute(InputInterface $input, OutputInterface $output) { ...@@ -58,6 +58,8 @@ protected function execute(InputInterface $input, OutputInterface $output) {
* Path to dump script. * Path to dump script.
*/ */
protected function runScript(Connection $connection, $script) { protected function runScript(Connection $connection, $script) {
$old_key = Database::setActiveConnection($connection->getKey());
if (substr($script, -3) == '.gz') { if (substr($script, -3) == '.gz') {
$script = "compress.zlib://$script"; $script = "compress.zlib://$script";
} }
...@@ -67,6 +69,7 @@ protected function runScript(Connection $connection, $script) { ...@@ -67,6 +69,7 @@ protected function runScript(Connection $connection, $script) {
catch (SchemaObjectExistsException $e) { catch (SchemaObjectExistsException $e) {
throw new \RuntimeException('An existing Drupal installation exists at this location. Try removing all tables or changing the database prefix in your settings.php file.'); throw new \RuntimeException('An existing Drupal installation exists at this location. Try removing all tables or changing the database prefix in your settings.php file.');
} }
Database::setActiveConnection($old_key);
} }
} }
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
namespace Drupal\Tests\system\Kernel\Scripts; namespace Drupal\Tests\system\Kernel\Scripts;
use Drupal\Core\Command\DbImportCommand; use Drupal\Core\Command\DbImportCommand;
use Drupal\Core\Config\DatabaseStorage;
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
...@@ -54,20 +53,25 @@ class DbImportCommandTest extends KernelTestBase { ...@@ -54,20 +53,25 @@ class DbImportCommandTest extends KernelTestBase {
/** /**
* Test the command directly. * Test the command directly.
*
* @requires extension pdo_sqlite
*/ */
public function testDbImportCommand() { public function testDbImportCommand() {
/** @var \Drupal\Core\Database\Connection $connection */ $connection_info = array(
$connection = $this->container->get('database'); 'driver' => 'sqlite',
// Drop tables to avoid conflicts. 'database' => ':memory:',
foreach ($this->tables as $table) { );
$connection->schema()->dropTable($table); Database::addConnectionInfo($this->databasePrefix, 'default', $connection_info);
}
$command = new DbImportCommand(); $command = new DbImportCommand();
$command_tester = new CommandTester($command); $command_tester = new CommandTester($command);
$command_tester->execute(['script' => __DIR__ . '/../../../fixtures/update/drupal-8.bare.standard.php.gz']); $command_tester->execute([
'script' => __DIR__ . '/../../../fixtures/update/drupal-8.bare.standard.php.gz',
'--database' => $this->databasePrefix,
]);
// The tables should now exist. // The tables should now exist.
$connection = Database::getConnection('default', $this->databasePrefix);
foreach ($this->tables as $table) { foreach ($this->tables as $table) {
$this->assertTrue($connection $this->assertTrue($connection
->schema() ->schema()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment