- 
                Notifications
    
You must be signed in to change notification settings  - Fork 6
 
Add support for Drush 10 #13
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
          
     Open
      
      
            manuee
  wants to merge
  15
  commits into
  8.x-1.x
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
3017760
  
      
      
   
  
    
  
  
  
 
  
      
    base: 8.x-1.x
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            15 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      aa2612b
              
                Issue #3017760: initial auto-generation of drush 9 commands
              
              
                malcomio 4dbc823
              
                fix coding standards issues mentioned by codesniffer
              
              
                malcomio e55727b
              
                basic conversion of dbsa command
              
              
                malcomio c084954
              
                basic conversion of dbsg command
              
              
                malcomio a6d5995
              
                coding standards fixes
              
              
                malcomio e008514
              
                coding standards fixes
              
              
                malcomio faf216e
              
                get options from I/O
              
              
                malcomio 1b3157c
              
                add drush back in dev dependencies
              
              
                malcomio 495b9e0
              
                make file optional in analyze command
              
              
                malcomio ddaa339
              
                Merge pull request #9 from malcomio/drush9
              
              
                manuee e6ef174
              
                #3017760 - Support drush 9 - Address review comments from #9
              
              
                vijaycs85 8a3196f
              
                Docblock update suggested by @manuee
              
              
                manuee 59081d1
              
                Docblock update.
              
              
                manuee 7fc7771
              
                Merge pull request #12 from vijaycs85/3017760
              
              
                manuee 5e2aec7
              
                Bumped Drush to 10.2.2 + Upgraded merge-yaml to 2.0.0-alpha1
              
              
                suzymasri File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| services: | ||
| database_sanitize.commands: | ||
| class: \Drupal\database_sanitize\Commands\DatabaseSanitizeCommands | ||
| arguments: ['@database_sanitize'] | ||
| tags: | ||
| - { name: drush.command } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| <?php | ||
| 
     | 
||
| namespace Drupal\database_sanitize\Commands; | ||
| 
     | 
||
| use Drupal\database_sanitize\DatabaseSanitize; | ||
| use Drush\Commands\DrushCommands; | ||
| 
     | 
||
| /** | ||
| * 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. | ||
| * | ||
| * 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 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 = $this->sanitizer->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 Sanitization entries for tables not specified on sanitize YML files.. | ||
| * | ||
| * @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 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'); | ||
| } | ||
| 
     | 
||
| 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 = $this->sanitizer->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
         | 
||
| } | ||
| 
     | 
||
| } | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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.
This actually never triggers because the parameter is mandatory on the command.