From e6ef174ab359b114bf3f222ee2340b306e6b6004 Mon Sep 17 00:00:00 2001 From: Vijaya Chandran Mani Date: Thu, 13 Dec 2018 12:33:09 +0000 Subject: [PATCH 1/3] #3017760 - Support drush 9 - Address review comments from #9 --- drush.services.yml | 1 + src/Commands/DatabaseSanitizeCommands.php | 40 +++++++++++++---------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/drush.services.yml b/drush.services.yml index 64cad3e..acaa9fb 100644 --- a/drush.services.yml +++ b/drush.services.yml @@ -1,5 +1,6 @@ services: database_sanitize.commands: class: \Drupal\database_sanitize\Commands\DatabaseSanitizeCommands + arguments: ['@database_sanitize'] tags: - { name: drush.command } diff --git a/src/Commands/DatabaseSanitizeCommands.php b/src/Commands/DatabaseSanitizeCommands.php index 998a75c..77b0362 100644 --- a/src/Commands/DatabaseSanitizeCommands.php +++ b/src/Commands/DatabaseSanitizeCommands.php @@ -2,21 +2,30 @@ namespace Drupal\database_sanitize\Commands; +use Drupal\database_sanitize\DatabaseSanitize; use Drush\Commands\DrushCommands; /** - * A Drush commandfile. - * - * In addition to this file, you need a drush.services.yml - * in root of your module, and a composer.json file that provides the name - * of the services file to use. - * - * See these files for an example of injecting Drupal services: - * - http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php - * - http://cgit.drupalcode.org/devel/tree/drush.services.yml + * Class DatabaseSanitizeCommands */ class DatabaseSanitizeCommands extends DrushCommands { + /** + * The sanitizer service instance. + * + * @var \Drupal\database_sanitize\DatabaseSanitize + */ + protected $sanitizer; + + /** + * DatabaseSanitizeCommands constructor. + * + * @param \Drupal\database_sanitize\DatabaseSanitize $sanitizer + */ + public function __construct(DatabaseSanitize $sanitizer) { + $this->sanitizer = $sanitizer; + } + /** * Analyze existing yml files. * @@ -37,13 +46,13 @@ class DatabaseSanitizeCommands extends DrushCommands { * * @throws \Exception */ - public function sanitizeAnalyze(array $options = ['file' => NULL, 'list' => NULL]) { + public function analyze(array $options = ['file' => NULL, 'list' => NULL]) { $file = $options['file']; if (!empty($file) && !file_exists($file)) { throw new \Exception(dt('File @file does not exist', ['@file' => $file])); } - $missing_tables = \Drupal::service('database_sanitize')->getUnspecifiedTables($file); + $missing_tables = $this->sanitizer->getUnspecifiedTables($file); if (!$missing_tables) { $this->logger()->info(dt('All database tables are already specified in sanitize YML files')); @@ -58,10 +67,7 @@ public function sanitizeAnalyze(array $options = ['file' => NULL, 'list' => NULL } /** - * Generates a database.sanitize.yml file. - * - * Generate database.sanitize.yml file for tables not specified on sanitize - * YML files. + * Generate Sanitization entries. * * @param array $options * An associative array of options whose values come from cli, aliases, @@ -80,7 +86,7 @@ public function sanitizeAnalyze(array $options = ['file' => NULL, 'list' => NULL * * @throws \Exception */ - public function sanitizeGenerate(array $options = ['file' => NULL, 'machine-name' => NULL]) { + public function generate(array $options = ['file' => NULL, 'machine-name' => NULL]) { $machine_name = $options['machine-name']; if (empty($machine_name)) { $machine_name = $this->io()->ask('Please provide the machine name to export the tables under'); @@ -91,7 +97,7 @@ public function sanitizeGenerate(array $options = ['file' => NULL, 'machine-name } $yml_file_path = $options['file']; - $missing_tables = \Drupal::service('database_sanitize')->getUnspecifiedTables($yml_file_path); + $missing_tables = $this->sanitizer->getUnspecifiedTables($yml_file_path); if (!$missing_tables) { $this->logger()->info(dt('All database tables are already specified in sanitize YML files')); return []; From 8a3196f2c36a839947443fc832a7a42d44eba978 Mon Sep 17 00:00:00 2001 From: Manuel Garcia Date: Thu, 13 Dec 2018 18:32:40 +0000 Subject: [PATCH 2/3] Docblock update suggested by @manuee Co-Authored-By: vijaycs85 --- src/Commands/DatabaseSanitizeCommands.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/DatabaseSanitizeCommands.php b/src/Commands/DatabaseSanitizeCommands.php index 77b0362..cb02ece 100644 --- a/src/Commands/DatabaseSanitizeCommands.php +++ b/src/Commands/DatabaseSanitizeCommands.php @@ -6,7 +6,7 @@ use Drush\Commands\DrushCommands; /** - * Class DatabaseSanitizeCommands + * Drush commands for Database Sanitize. */ class DatabaseSanitizeCommands extends DrushCommands { From 59081d1678bb9eb523211a8927316b8c09244b87 Mon Sep 17 00:00:00 2001 From: Manuel Garcia Date: Thu, 13 Dec 2018 18:33:01 +0000 Subject: [PATCH 3/3] Docblock update. Co-Authored-By: vijaycs85 --- src/Commands/DatabaseSanitizeCommands.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/DatabaseSanitizeCommands.php b/src/Commands/DatabaseSanitizeCommands.php index cb02ece..09af7bf 100644 --- a/src/Commands/DatabaseSanitizeCommands.php +++ b/src/Commands/DatabaseSanitizeCommands.php @@ -67,7 +67,7 @@ public function analyze(array $options = ['file' => NULL, 'list' => NULL]) { } /** - * Generate Sanitization entries. + * Generates Sanitization entries for tables not specified on sanitize YML files.. * * @param array $options * An associative array of options whose values come from cli, aliases,