-
Notifications
You must be signed in to change notification settings - Fork 6
Issue #3017760: Support drush 9 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
aa2612b
4dbc823
e55727b
c084954
a6d5995
e008514
faf216e
1b3157c
495b9e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| services: | ||
| database_sanitize.commands: | ||
| class: \Drupal\database_sanitize\Commands\DatabaseSanitizeCommands | ||
| tags: | ||
| - { name: drush.command } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| <?php | ||
|
|
||
| namespace Drupal\database_sanitize\Commands; | ||
|
|
||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This docblock needs updating to describe the class itself. |
||
| */ | ||
| class DatabaseSanitizeCommands extends DrushCommands { | ||
|
|
||
| /** | ||
| * Analyze existing yml files. | ||
| * | ||
| * Compares existing database.sanitize.yml files on the site installation | ||
| * against existing database tables. | ||
| * | ||
| * @param array $options | ||
| * An associative array of options whose values come from cli, aliases, | ||
| * config, etc. | ||
| * | ||
| * @option file | ||
| * The full path to a sanitize YML file. | ||
| * @option list | ||
| * List the table names. | ||
| * | ||
| * @command db:sanitize-analyze | ||
| * @aliases dbsa,db-sanitize-analyze | ||
| * | ||
| * @throws \Exception | ||
| */ | ||
| public function sanitizeAnalyze(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); | ||
|
|
||
| if (!$missing_tables) { | ||
| $this->logger()->info(dt('All database tables are already specified in sanitize YML files')); | ||
| return; | ||
| } | ||
|
|
||
| $this->logger()->warning(dt('There are @count tables not defined on sanitize YML files', ['@count' => count($missing_tables)])); | ||
|
|
||
| if (!empty($options['list'])) { | ||
| $this->logger()->warning(implode("\n", $missing_tables)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Generates a database.sanitize.yml file. | ||
| * | ||
| * Generate database.sanitize.yml file for tables not specified on sanitize | ||
| * YML files. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't correct, we do not generate a |
||
| * | ||
| * @param array $options | ||
| * An associative array of options whose values come from cli, aliases, | ||
| * config, etc. | ||
| * | ||
| * @option file | ||
| * The full path to a sanitize YML file. | ||
| * @option machine-name | ||
| * The machine name to export the tables under. | ||
| * | ||
| * @command db:sanitize-generate | ||
| * @aliases dbsg,db-sanitize-generate | ||
| * | ||
| * @return array | ||
| * Array of sanitization entries - TODO: more info. | ||
| * | ||
| * @throws \Exception | ||
| */ | ||
| public function sanitizeGenerate(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'); | ||
| } | ||
|
|
||
| if (empty($options['file'])) { | ||
| $options['file'] = $this->io()->ask('Please provide the full path to a sanitize YML file'); | ||
| } | ||
|
|
||
| $yml_file_path = $options['file']; | ||
| $missing_tables = \Drupal::service('database_sanitize')->getUnspecifiedTables($yml_file_path); | ||
| if (!$missing_tables) { | ||
| $this->logger()->info(dt('All database tables are already specified in sanitize YML files')); | ||
| return []; | ||
| } | ||
|
|
||
| $content = [ | ||
| 'sanitize' => [ | ||
| $machine_name => [], | ||
| ], | ||
| ]; | ||
| foreach ($missing_tables as $table) { | ||
| $content['sanitize'][$machine_name][$table] = [ | ||
| 'description' => "Sanitization entry for {$table}. Generated by drush db-sanitize-generate.", | ||
| 'query' => "TRUNCATE TABLE {$table}", | ||
| ]; | ||
| } | ||
|
|
||
| return $content; | ||
manuee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets inject here the
database_sanitizeservice:arguments: ['@database_sanitize']Then add a constructor like on http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea - I probably won't get time to work on this over the next few days, so if you have time please could you take this forward?