Skip to content

Commit

Permalink
Support DB prefix in sql sanitize
Browse files Browse the repository at this point in the history
  • Loading branch information
bjeavons authored and weitzman committed Sep 13, 2014
1 parent 5d5d390 commit fdffc65
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions commands/sql/sql.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ function sql_drush_command() {
'description' => "Run sanitization operations on the current database.",
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'options' => array(
'db-prefix' => 'Enable replacement of braces in sanitize queries.',
'sanitize-password' => 'The password to assign to all accounts in the sanitization operation, or "no" to keep passwords unchanged. Default is "password".',
'sanitize-email' => 'The pattern for test email addresses in the sanitization operation, or "no" to keep email addresses unchanged. May contain replacement patterns %uid, %mail or %name. Default is "user+%uid@localhost".',
) + $db_url,
Expand Down Expand Up @@ -534,6 +535,9 @@ function drush_sql_cli() {
*/
function drush_sql_sanitize() {
drush_sql_bootstrap_further();
if (drush_get_option('db-prefix')) {
drush_bootstrap_max(DRUSH_BOOTSTRAP_DRUPAL_DATABASE);
}
drush_include(DRUSH_BASE_PATH . '/commands/sql', 'sync.sql');
drush_command_invoke_all('drush_sql_sync_sanitize', 'default');
$options = drush_get_context('post-sync-ops');
Expand All @@ -552,6 +556,15 @@ function drush_sql_sanitize() {

$sanitize_query = '';
foreach($options as $id => $data) {
// Enable prefix processing when db-prefix option is used.
if (drush_get_option('db-prefix')) {
if (drush_drupal_major_version() >= 7) {
$data['query'] = Database::getConnection()->prefixTables($data['query']);
}
else {
$data['query'] = db_prefix_tables($data['query']);
}
}
$sanitize_query .= $data['query'] . " ";
}
if ($sanitize_query) {
Expand Down

0 comments on commit fdffc65

Please sign in to comment.