Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions drush/database_sanitize.drush8.inc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ function database_sanitize_drush_command() {
'required' => FALSE,
],
],
'outputformat' => [
'default' => 'yaml',
'output-data-type' => 'format-yaml',
'pipe-format' => 'json',
],
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL,
];

Expand Down Expand Up @@ -81,21 +86,33 @@ function database_sanitize_drush_command() {
*/
function database_sanitize_analyze() {
$yml_file_path = drush_get_option('file');
$machine_readable = drush_get_option('format') || drush_get_context('DRUSH_PIPE');
if ($yml_file_path && !file_exists($yml_file_path)) {
return drush_set_error(dt('File does not exist @file', ['@file' => $yml_file_path]));
}

$result = FALSE;
$missing_tables = \Drupal::service('database_sanitize')->getUnspecifiedTables($yml_file_path);

if (!$missing_tables) {
drush_log(dt('All database tables are already specified in sanitize YML files'), 'ok');
return;
$result = TRUE;
if (!$machine_readable) {
drush_log(dt('All database tables are already specified in sanitize YML files'), 'ok');
}
}

drush_log(dt('There are @count tables not defined on sanitize YML files', ['@count' => count($missing_tables)]), 'warning');
elseif (!$machine_readable) {
drush_log(dt('There are @count tables not defined on sanitize YML files', ['@count' => count($missing_tables)]), 'warning');
}

if (drush_get_option('list')) {
drush_log(implode("\n", $missing_tables), 'warning');
return $missing_tables;
}

if ($machine_readable) {
return [
'result' => $result,
];
}
}

Expand Down