You are here

function database_sanitize_generate in Database Sanitize 7

Same name and namespace in other branches
  1. 8 drush/database_sanitize.drush8.inc \database_sanitize_generate()

Command callback for db-sanitize-generate.

1 string reference to 'database_sanitize_generate'
database_sanitize_drush_command in drush/database_sanitize.drush8.inc
Implements hook_drush_command().

File

drush/database_sanitize.drush8.inc, line 103
Drush Database Sanitize commands.

Code

function database_sanitize_generate() {
  $machine_name = drush_get_option('machine-name');
  if (empty($machine_name)) {
    return drush_set_error(dt('You must specify a machine-name'));
  }
  $yml_file_path = drush_get_option('file');
  require __DIR__ . '/../inc/database_sanitize.inc';
  $missing_tables = database_sanitize_get_unspecified_tables($yml_file_path);
  if (!$missing_tables) {
    drush_log(dt('All database tables are already specified in sanitize YML files'), 'ok');
    return;
  }
  $content = [
    'sanitize' => [
      $machine_name => [],
    ],
  ];
  foreach ($missing_tables as $table) {
    $content['sanitize'][$machine_name][$table] = [
      'description' => "Sanitization entry for {$table}. Generated by drush db-sanitize-generate.",
      'query' => "TRUNCATE TABLE {$table}",
    ];
  }
  return $content;
}