Drush Sanitize Hook

Created on 8 April 2020, about 4 years ago
Updated 6 July 2023, 12 months ago

Realname has the potential to contain sensitive personal information in the realname database table. We should provide a simple way for this information to be removed when, for example, copying databases from different environments.

drush sql-sanitize provides a framework for this to be done.

I have created a patch which hooks into this command and truncate the realname table.

✨ Feature request
Status

Needs work

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom Coops_ London

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • heddn Nicaragua

    Can we add a simple test to confirm this is working as expected?

  • Status changed to Needs review 12 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 8
    last update 12 months ago
    run-tests.sh fatal error
  • 🇮🇳India sumit-k

    Hi, I have reviewed the provided patch and added a test for the "drush sanitize" command. Please find the updated patch attached for review.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update 12 months ago
    run-tests.sh fatal error
  • Status changed to Needs work 12 months ago
  • heddn Nicaragua
    +++ b/composer.json
    @@ -20,5 +20,12 @@
    +  "extra": {
    

    Can we add a require-dev section for drush/drush?

  • 🇮🇳India sumit-k

    Sure, Sharing a new patch. Please review

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update 12 months ago
    5 pass
  • heddn Nicaragua

    This is looking really nice. Just a few small nits.

    1. +++ b/composer.json
      @@ -18,7 +18,23 @@
      +        "drush.services.yml": "^9"
      

      should this include an OR and include drush 10, 11 and 12 as well? Or is the version not needed at all? Actually, test things but I don't think the entry is needed at all. See my later point about changing class namespace.

    2. +++ b/src/Commands/RealnameSanitizeCommand.php
      @@ -0,0 +1,88 @@
      +   * @hook post-command sql-sanitize
      
      +++ b/tests/src/Functional/RealnameBasicTest.php
      @@ -183,4 +184,14 @@ class RealnameBasicTest extends BrowserTestBase {
      +    $this->drush('sql-sanitize', [], ['sanitize-realname' => 1]);
      

      Can we add an assert about the messages to include, "Truncate realname table."?

      $this->assertStringContainsString('Truncate realname table.', $this->getOutput());
      
    3. +++ b/composer.json
      @@ -18,7 +18,23 @@
      +        "drush.services.yml": "^9"
      
      +++ b/drush.services.yml
      @@ -0,0 +1,6 @@
      +    class: \Drupal\realname\Commands\RealnameSanitizeCommand
      
      +++ b/src/Commands/RealnameSanitizeCommand.php
      @@ -0,0 +1,88 @@
      +namespace Drupal\realname\Commands;
      

      If the namespace changes to Drupal\realname\Drush and implements a static create() method, then I don't think any of this is needed. It will get auto bootstrapped and discovered.

      public static function create(ContainerInterface $container): self {
          return new static(
            $container->get('database')
          );
        }
      
  • 🇮🇳India sumit-k

    Thanks for the review. Sharing new patch covered point 2.
    Regarding points 1 and 3.

    +++ b/composer.json
    @@ -18,7 +18,23 @@
    +        "drush.services.yml": "^9"

    It seems it will be required for Drush 10.

    Based on the provided documentation https://git.uwaterloo.ca/libraries/drush/-/blob/11.x/docs/commands.md, it appears that including the drush.services.yml file and the /src/Drupal/Commands directory is indeed required

    Not sure about dependency injection based on the following document it has two way to use dependency injection
    https://git.uwaterloo.ca/libraries/drush/-/blob/11.x/docs/dependency-inj...

    Please correct me if my understanding is not clear.

  • heddn Nicaragua

    https://git.drupalcode.org/project/migrate_tools/-/blob/6.0.x/src/Drush/... has passing green tests w/ drush 11 and drush 12. I had to limit support to at least drush 11 as I couldn't get drush 10 and 12 to both support things at the same time. But since drush 10 no longer is supported, I think that is OK.

Production build 0.69.0 2024