Skip to content

Commit

Permalink
Thin sqlVersion.php ahead of its removal.
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman committed Feb 5, 2017
1 parent ff49a04 commit f3f764d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 58 deletions.
24 changes: 0 additions & 24 deletions includes/environment.inc
Original file line number Diff line number Diff line change
Expand Up @@ -369,30 +369,6 @@ function drush_valid_root($root) {
return $bootstrap_class != NULL;
}

/**
* Tests the currently loaded database credentials to ensure a database connection can be made.
*
* @return bool
* TRUE if database credentials are valid.
*/
function drush_valid_db_credentials() {
try {
$sql = drush_sql_get_class();
if (!$sqlVersion = drush_sql_get_version()) {
drush_log(dt('While checking DB credentials, could not instantiate SQLVersion class.'), 'debug');
return FALSE;
}
if (!$sqlVersion->hasPDO()) {
return FALSE;
}
return $sql->query('SELECT 1;');
}
catch (Exception $e) {
drush_log(dt('Checking DB credentials yielded error: @e', array('@e' => $e->getMessage())), 'debug');
return FALSE;
}
}

/**
* Determine a proper way to call drush again
*
Expand Down
9 changes: 8 additions & 1 deletion lib/Drush/Boot/DrupalBoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,14 @@ function bootstrap_drupal_configuration() {
* phase.
*/
function bootstrap_drupal_database_validate() {
if (!drush_valid_db_credentials()) {
// Drupal requires PDO, and Drush requires php 5.6+ which ships with PDO
// but PHP may be compiled with --disable-pdo.
if (!class_exists('\PDO')) {
drush_log(dt('PDO support is required.'), LogLevel::BOOTSTRAP);
return FALSE;
}
$sql = drush_sql_get_class();
if (!$sql->query('SELECT 1;')) {
return drush_bootstrap_error('DRUSH_DRUPAL_DB_ERROR');
}
return TRUE;
Expand Down
4 changes: 2 additions & 2 deletions lib/Drush/Commands/sql/SqlCommands.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Drush\Commands\sql;

use Drupal\Core\Database\Database;
use Drush\Commands\DrushCommands;

class SqlCommands extends DrushCommands {
Expand All @@ -17,8 +18,7 @@ class SqlCommands extends DrushCommands {
public function conf($options = ['format' => 'yaml', 'all' => FALSE, 'show-passwords' => FALSE]) {
drush_bootstrap_max(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION);
if ($options['all']) {
$sqlVersion = drush_sql_get_version();
$return = $sqlVersion->getAll();
$return = Database::getAllConnectionInfo();
foreach ($return as $key1 => $value) {
foreach ($value as $key2 => $spec) {
if (!$options['show-passwords']) {
Expand Down
6 changes: 0 additions & 6 deletions lib/Drush/Sql/Sql7.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,4 @@ public function get_db_spec() {
}
return $db_spec;
}

public function getAll() {
if (isset($GLOBALS['databases'])) {
return $GLOBALS['databases'];
}
}
}
4 changes: 0 additions & 4 deletions lib/Drush/Sql/Sql8.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,4 @@ public function get_db_spec() {
}
return $db_spec;
}

public function getAll() {
return Database::getAllConnectionInfo();
}
}
21 changes: 0 additions & 21 deletions lib/Drush/Sql/SqlVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,4 @@ class SqlVersion {
* An array specifying a database connection.
*/
public function get_db_spec() {}

/*
* Return all configured DB connections by inspecting the global environment (D6/7) or the DB API (D8+).
*
* @return array $all
* An array specifying one or more database connections.
*/
public function getAll() {}

/*
* Validate that required PDO PHP extension is available.
*/
public function hasPDO() {
// Drupal requires PDO, and Drush requires php 5.6+ which ships with PDO
// but PHP may be compiled with --disable-pdo.
if (!class_exists('\PDO')) {
drush_log(dt('PDO support is required.'), LogLevel::BOOTSTRAP);
return FALSE;
}
return TRUE;
}
}

0 comments on commit f3f764d

Please sign in to comment.