Sanitize profile fields on drush sql:sanitize

Created on 18 December 2020, about 4 years ago
Updated 16 January 2024, 12 months ago

Problem/Motivation

I was wondering if there was interest in adding some drush sql:sanitize integration to the profile module. By default that command sanitizes a variety of core field types if they're attached to the user entity (with the option of opting specific fields out). Do people think it makes sense to do the same thing with profiles?

Proposed resolution

Sanitize profile fields in the same way as user fields.

Thanks!

Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom AndyF

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.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    Patch Failed to Apply
  • 🇸🇮Slovenia primsi

    Here is an inital patch based on the SanitizeUserFieldsCommands.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    23 pass
  • 🇸🇮Slovenia primsi

    Patch had no content ... probably wrong git diff > ... Fixing.

  • Status changed to Needs work over 1 year ago
  • 🇨🇭Switzerland berdir Switzerland
    1. +++ b/src/Commands/SanitizeProfileFieldsCommands.php
      @@ -0,0 +1,166 @@
      +    foreach ($profile_types as $profile_type) {
      

      looping over profile types is problematic needed, you'd update the same tables multiple times if they are shared. I see you need it for the default value, that's unfortunate.

      a reason to do that would be to support specific bundle include/exclude (possibly later), but then you need to add a bundle condition to the query.

      or we do a separate loop first to build default values and only process bundle fields once, by tracking values[$field_name] and if it's already set or not.

    2. +++ b/src/Commands/SanitizeProfileFieldsCommands.php
      @@ -0,0 +1,166 @@
      +        $table = 'profile__' . $key;
      

      this is copied, but it should really use the api to get the field name. Long field names can result in a hashed table names and then this will fail.

      Also, we need to do revision tables as well.

      You want to get the table mapping:

      $table_mapping = \Drupal::entityTypeManager()
      ->getStorage($entity_type_id)
      ->getTableMapping();

      And then use getDedicatedDataTableName() and getDedicatedRevisionTableName(). They are not on the default interface, so you want to do an instanceof check for the specific class and skip if that's not it.

  • 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 5.7
    last update over 1 year ago
    23 pass
  • 🇸🇮Slovenia primsi

    Thanks. Implemented suggestions.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    23 pass
  • 🇸🇮Slovenia primsi

    Execution mistakenly left out after that bit of refactoring.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update about 1 year ago
    23 pass
  • 🇸🇮Slovenia primsi

    Adding an option to truncate value length (not sure about the naming). If a profile uses separate fields for let's say name and surname, this can result in quite long first names and last names.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update about 1 year ago
    23 pass
  • 🇸🇮Slovenia primsi

    After discussing with @Berdir, this could also be an option: that is to provide a way to override the value.

    Interdiff is against #9

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 12 months ago
    23 pass
  • 🇸🇮Slovenia primsi

    Smaller update

Production build 0.71.5 2024