Skip to content

Commit

Permalink
fix Drush command sql-query with option "--db-prefix" in use (#3529)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
deminy authored and weitzman committed May 28, 2018
1 parent ce6bdc4 commit 6ba88ce
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/Drush/Sql/SqlBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drush\Sql;

use Drupal\Core\Database\Database;
use Drush\Log\LogLevel;
use Webmozart\PathUtil\Path;

Expand Down Expand Up @@ -201,8 +200,12 @@ public function query_prefix($query) {
if (drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_DATABASE)) {
// Enable prefix processing which can be dangerous so off by default. See http://drupal.org/node/1219850.
if (drush_get_option('db-prefix')) {
if (drush_drupal_major_version() >= 7) {
$query = Database::getConnection()->prefixTables($query);
$drupal_major_version = drush_drupal_major_version();
if ($drupal_major_version >= 8) {
$query = \Drupal\Core\Database\Database::getConnection()->prefixTables($query);
}
elseif ($drupal_major_version == 7) {
$query = \Database::getConnection()->prefixTables($query);
}
else {
$query = db_prefix_tables($query);
Expand Down

0 comments on commit 6ba88ce

Please sign in to comment.