Commit 5132930c authored by webchick's avatar webchick

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

parent 0eed649b
......@@ -58,6 +58,8 @@ protected function execute(InputInterface $input, OutputInterface $output) {
* Path to dump script.
*/
protected function runScript(Connection $connection, $script) {
$old_key = Database::setActiveConnection($connection->getKey());
if (substr($script, -3) == '.gz') {
$script = "compress.zlib://$script";
}
......@@ -67,6 +69,7 @@ protected function runScript(Connection $connection, $script) {
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.');
}
Database::setActiveConnection($old_key);
}
}
......@@ -8,7 +8,6 @@
namespace Drupal\Tests\system\Kernel\Scripts;
use Drupal\Core\Command\DbImportCommand;
use Drupal\Core\Config\DatabaseStorage;
use Drupal\Core\Database\Database;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\Console\Tester\CommandTester;
......@@ -54,20 +53,25 @@ class DbImportCommandTest extends KernelTestBase {
/**
* Test the command directly.
*
* @requires extension pdo_sqlite
*/
public function testDbImportCommand() {
/** @var \Drupal\Core\Database\Connection $connection */
$connection = $this->container->get('database');
// Drop tables to avoid conflicts.
foreach ($this->tables as $table) {
$connection->schema()->dropTable($table);
}
$connection_info = array(
'driver' => 'sqlite',
'database' => ':memory:',
);
Database::addConnectionInfo($this->databasePrefix, 'default', $connection_info);
$command = new DbImportCommand();
$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.
$connection = Database::getConnection('default', $this->databasePrefix);
foreach ($this->tables as $table) {
$this->assertTrue($connection
->schema()
......
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