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. Runs 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 464
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');
  $operations = drush_get_context('post-sync-ops');
  if (!empty($operations)) {
    if (!drush_get_context('DRUSH_SIMULATE')) {
      $messages = _drush_sql_get_post_sync_messages();
      if ($messages) {
        drush_print();
        drush_print($messages);
      }
    }
    $queries = array_column($operations, 'query');
    $sanitize_query = implode(" ", $queries);
  }
  if (!drush_confirm(dt('Do you really want to sanitize the current database?'))) {
    return drush_user_abort();
  }

  if ($sanitize_query) {
    $sql = drush_sql_get_class();
    $sanitize_query = $sql->query_prefix($sanitize_query);
    $result = $sql->query($sanitize_query);
    if (!$result) {
      return drush_set_error('DRUSH_SQL_NO_QUERY', dt('Sanitize query failed.'));
    }
  }
}