From c0bc2e9bd86a14e09bc586822a32d94e31313342 Mon Sep 17 00:00:00 2001 From: Manuel Garcia Date: Tue, 11 Jun 2019 09:16:29 +0100 Subject: [PATCH 1/2] [EDN-3550] Add pipe option to dbsa --- drush/database_sanitize.drush8.inc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drush/database_sanitize.drush8.inc b/drush/database_sanitize.drush8.inc index 590a5ab..2c946b5 100644 --- a/drush/database_sanitize.drush8.inc +++ b/drush/database_sanitize.drush8.inc @@ -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, ]; @@ -86,17 +91,20 @@ function database_sanitize_analyze() { } $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; + return [ + 'result' => TRUE, + ]; } 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; } + return [ + 'result' => FALSE, + ]; } /** From dad1add36d8803f3a9721174b3f2b393aa835983 Mon Sep 17 00:00:00 2001 From: Manuel Garcia Date: Thu, 13 Jun 2019 09:33:07 +0100 Subject: [PATCH 2/2] [EDN-3550] Don't output messages when machine readable is requtested on dbsa --- drush/database_sanitize.drush8.inc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drush/database_sanitize.drush8.inc b/drush/database_sanitize.drush8.inc index 2c946b5..e470ad0 100644 --- a/drush/database_sanitize.drush8.inc +++ b/drush/database_sanitize.drush8.inc @@ -86,25 +86,34 @@ 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, - ]; + $result = TRUE; + if (!$machine_readable) { + drush_log(dt('All database tables are already specified in sanitize YML files'), 'ok'); + } + } + + elseif (!$machine_readable) { + drush_log(dt('There are @count tables not defined on sanitize YML files', ['@count' => count($missing_tables)]), 'warning'); } - drush_log(dt('There are @count tables not defined on sanitize YML files', ['@count' => count($missing_tables)]), 'warning'); if (drush_get_option('list')) { return $missing_tables; } - return [ - 'result' => FALSE, - ]; + + if ($machine_readable) { + return [ + 'result' => $result, + ]; + } } /**