Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions drush.services.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
services:
database_sanitize.commands:
class: \Drupal\database_sanitize\Commands\DatabaseSanitizeCommands
arguments: ['@database_sanitize']
tags:
- { name: drush.command }
40 changes: 23 additions & 17 deletions src/Commands/DatabaseSanitizeCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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'));
Expand All @@ -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,
Expand All @@ -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');
Expand All @@ -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 [];
Expand Down