Drush Sanitize Hook

Created on 8 April 2020, over 4 years ago
Updated 2 March 2023, almost 2 years 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.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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 over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 8
    last update over 1 year 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 over 1 year ago
    run-tests.sh fatal error
  • Status changed to Needs work over 1 year 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 over 1 year 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.

  • 🇳🇱Netherlands ecvandenberg

    After updating this module to 2.0.0 the #8 patch does not apply anymore. A fix is very welcome...

Production build 0.71.5 2024