function drush_sql_sanitize

8.0.x sql.drush.inc drush_sql_sanitize()
6.x sql.drush.inc drush_sql_sanitize()
7.x sql.drush.inc drush_sql_sanitize()
4.x sql.drush.inc drush_sql_sanitize()
5.x sql.drush.inc drush_sql_sanitize()
master sql.drush.inc drush_sql_sanitize()

Command callback. Run's the sanitization operations on the current database.

See also

hook_drush_sql_sync_sanitize() for adding custom sanitize routines.

File

commands/sql/sql.drush.inc, line 454
Drush sql commands

Code

function drush_sql_sanitize() {
  drush_sql_bootstrap_further();
  if (drush_get_option('db-prefix')) {
    drush_bootstrap_max(DRUSH_BOOTSTRAP_DRUPAL_DATABASE);
  }

  drush_command_invoke_all('drush_sql_sync_sanitize', 'default');
  $options = drush_get_context('post-sync-ops');
  if (!empty($options)) {
    if (!drush_get_context('DRUSH_SIMULATE')) {
      $messages = _drush_sql_get_post_sync_messages();
      if ($messages) {
        drush_print();
        drush_print($messages);
      }
    }
  }
  if (!drush_confirm(dt('Do you really want to sanitize the current database?'))) {
    return drush_user_abort();
  }

  $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) {
    $sql = drush_sql_get_class();
    return $sql->query($sanitize_query);
  }
}