Problem/Motivation

1. The module generates Drupal\migrate\Plugin\Exception\BadPluginDefinitionException after migrating to Drupal9

Steps to reproduce

1. Install user hash module in Drupal7 site.
2. Migrate the site to Drupal 9.
3. BadPluginException occurs
4. Check for the user hash configuration in Drupal 9.
5. The configuration on Drupal 9 doesn't match the Drupal 7 configuration.

Proposed resolution

NA

Remaining tasks

NA

User interface changes

NA

API changes

NA

Data model changes

NA

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

srishti.bankar created an issue. See original summary.

srishtiiee’s picture

Attached a patch here

srishtiiee’s picture

Issue summary: View changes
Wim Leers’s picture

Status: Active » Reviewed & tested by the community
  1. +++ b/migrations/user_hash_settings.yml
    @@ -0,0 +1,17 @@
    +  source_module: user_hash
    

    I first thought this was unnecessary, but … it is necessary! This variable is from the user_hash module, and by default the variable plugin looks at variables from the system module.

    So … this makes perfect sense :)

  2. +++ b/migrations/user_hash_settings.yml
    @@ -0,0 +1,17 @@
    +id: user_hash_settings
    +label: User hash configuration
    +migration_tags:
    +  - Drupal 7
    +  - Configuration
    

    The configuration for the user_hash module was not yet being migrated!

    Without these settings, it's impossible to correctly interpret the hashes … because you need to know the settings that generated them in order for the migrated values to make sense.

  3. +++ b/src/Plugin/migrate/source/d7/UserHash.php
    @@ -8,7 +8,8 @@ use Drupal\migrate\Plugin\migrate\source\SqlBase;
      * @MigrateSource(
    - *   id = "d7_user_hash"
    + *   id = "d7_user_hash",
    + *   source_module = "user_hash"
      * )
    

    If you do not specify the source_module key, then the source plugin is available always, even when the user_hash module is not installed on the source site.

    IOW: if you install the user_hash module in Drupal 8 or 9 while running a migration, the absence of this key would cause a SQL error — because the hash column will not exist in the users table.

  4. +++ b/src/Plugin/migrate/source/d7/UserHash.php
    @@ -20,7 +21,8 @@ class UserHash extends SqlBase {
       public function query() {
         $query = $this->select('users', 'u')
    -      ->fields('u', ['uid', 'hash']);
    +      ->fields('u', ['uid', 'hash'])
    +      ->condition('u.uid', 0, '>');
         return $query;
    

    Drupal core does not migrate user zero (the anonymous user). In Drupal 8|9, this is configuration, not an actual User entity.

    See \Drupal\user\Plugin\migrate\source\d7\User::query(), which also does:

      public function query() {
        return $this->select('users', 'u')
          ->fields('u')
          ->condition('u.uid', 0, '>');
      }
    

    As you can see: exactly the same condition!

    Without this added condition, the user_hash migration always reports one more row to migrate than there are users to migrate! 😨😅

  • jurgenhaas committed ded89d7 on 2.0.x
    Issue #3232037 by srishti.bankar, Wim Leers: Configuration missing while...
jurgenhaas’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patch @srishti.bankar and for the review @Wim Leers, just committet the changes and will publish a new release soon.

srishtiiee’s picture

Issue summary: View changes
srishtiiee’s picture

Issue summary: View changes
srishtiiee’s picture

Issue summary: View changes

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.