Skip to content

Commit 6ba88ce

Browse files
deminyweitzman
authored andcommitted
fix Drush command sql-query with option "--db-prefix" in use (#3529)
* fix namespace for Drush command sql-query with option "--db-prefix" in use * [#2882] make option "--db-prefix" work with all major versions of Drupal * [#2882] store function call result to a variable to avoid multiple function calls
1 parent ce6bdc4 commit 6ba88ce

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/Drush/Sql/SqlBase.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Drush\Sql;
44

5-
use Drupal\Core\Database\Database;
65
use Drush\Log\LogLevel;
76
use Webmozart\PathUtil\Path;
87

@@ -201,8 +200,12 @@ public function query_prefix($query) {
201200
if (drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_DATABASE)) {
202201
// Enable prefix processing which can be dangerous so off by default. See http://drupal.org/node/1219850.
203202
if (drush_get_option('db-prefix')) {
204-
if (drush_drupal_major_version() >= 7) {
205-
$query = Database::getConnection()->prefixTables($query);
203+
$drupal_major_version = drush_drupal_major_version();
204+
if ($drupal_major_version >= 8) {
205+
$query = \Drupal\Core\Database\Database::getConnection()->prefixTables($query);
206+
}
207+
elseif ($drupal_major_version == 7) {
208+
$query = \Database::getConnection()->prefixTables($query);
206209
}
207210
else {
208211
$query = db_prefix_tables($query);

0 commit comments

Comments
 (0)