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..09af7bf 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 + * Drush commands for Database Sanitize. */ 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. + * 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, @@ -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 [];