You are here

protected function DbImportCommand::runScript in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Command/DbImportCommand.php \Drupal\Core\Command\DbImportCommand::runScript()

Run the database script.

Parameters

\Drupal\Core\Database\Connection $connection: Connection used by the script when included.

string $script: Path to dump script.

1 call to DbImportCommand::runScript()
DbImportCommand::execute in core/lib/Drupal/Core/Command/DbImportCommand.php
Executes the current command.

File

core/lib/Drupal/Core/Command/DbImportCommand.php, line 60
Contains \Drupal\Core\Command\DbImportCommand.

Class

DbImportCommand
Provides a command to import the current database from a script.

Namespace

Drupal\Core\Command

Code

protected function runScript(Connection $connection, $script) {
  $old_key = Database::setActiveConnection($connection
    ->getKey());
  if (substr($script, -3) == '.gz') {
    $script = "compress.zlib://{$script}";
  }
  try {
    require $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);
}