Problem/Motivation

When migmag_process is installed but migrate_drupal is not, installing any module that runs a migration in hook_install causes a fatal PHP error:

Fatal error: The modifiers of the trait method getLegacyDrupalVersion() are changed,
but this method does not exist.
Error in .../migmag/src/Traits/MigMagMigrationConfigurationTrait.php on line 12


This seems to be caused by a 3-way interaction between PHP's class loading, Drupal's plugin discovery mechanism, and the compatibility shim in MigMagMigrationConfigurationTrait.php.

Drupal's AttributeClassDiscovery (introduced in Drupal 11.x) registers a MissingClassDetectionClassLoader as a fallback autoloader during plugin discovery. When it encounters a trait from a module that is not installed, instead of crashing it registers an empty stub:

class_alias(StubTrait::class, 'Drupal\migrate_drupal\MigrationConfigurationTrait');


This stub has no methods. Later in the same discovery scan, MigMagMigrationConfigurationTrait.php is loaded and evaluates its guard condition:

if (trait_exists(MigrationConfigurationTrait::class, FALSE)) {


The FALSE argument means "don't autoload, just check if it's already registered." Because the stub was registered moments earlier, this returns TRUE. The if branch fires and PHP tries to compile getLegacyDrupalVersion as private from the empty stub — which has no such method — causing the fatal error.

Steps to reproduce

  1. Install Drupal 11.x with migmag and migmag_process enabled. Do not install migrate_drupal.
  2. Use any module that has a hook_install with migration; here's a simple example:

    migmag_repro.info.yml:

    name: 'MigMag Repro'
    type: module
    description: 'Minimal reproduction case for migmag fatal error when migrate_drupal is not installed.'
    core_version_requirement: ^11
    package: Testing
    dependencies:
      - drupal:migrate
      - drupal:taxonomy
      - migmag:migmag_process
        

    migmag_repro.install:

    <?php
    
    use Drupal\migrate\MigrateExecutable;
    use Drupal\migrate\MigrateMessage;
    
    function migmag_repro_install() {
      $migrations = \Drupal::service('plugin.manager.migration')->createInstancesByTag('migmag_repro');
      foreach ($migrations as $migration) {
        $executable = new MigrateExecutable($migration, new MigrateMessage());
        $executable->import();
      }
    }
        

    migrations/migmag_repro.yml:

    id: migmag_repro
    label: 'MigMag Repro'
    migration_tags:
      - migmag_repro
    source:
      plugin: embedded_data
      data_rows:
        - id: 1
          name: 'Repro Term'
      ids:
        id:
          type: integer
    process:
      vid:
        plugin: default_value
        default_value: migmag_repro
      name: name
    destination:
      plugin: entity:taxonomy_term
    dependencies:
      enforced:
        module:
          - migrate
        

    config/install/taxonomy.vocabulary.migmag_repro.yml:

    langcode: en
    status: true
    dependencies: {}
    name: 'MigMag Repro'
    vid: migmag_repro
    description: ''
    hierarchy: 0
    weight: 0
        
  3. Run drush en migmag_repro. The fatal error fires immediately in hook_install.

Affected versions: migmag 1.8.4, Drupal 11.3.9, PHP 8.5.3

Proposed resolution

Add a method_exists check to the guard condition in src/Traits/MigMagMigrationConfigurationTrait.php. A stub registered by MissingClassDetectionClassLoader is an empty trait with no methods, so method_exists correctly distinguishes it from the real trait:

// Before:
if (trait_exists(MigrationConfigurationTrait::class, FALSE)) {

// After:
if (trait_exists(MigrationConfigurationTrait::class, FALSE) && method_exists(MigrationConfigurationTrait::class, 'getLegacyDrupalVersion')) {

This correctly handles all three possible states:

Scenario trait_exists method_exists Result
migrate_drupal installed TRUE TRUE if branch — uses real method ✓
migrate_drupal not installed, never scanned FALSE — else branch — returns FALSE ✓
migrate_drupal not installed, but stubbed by discovery TRUE FALSE else branch — returns FALSE ✓ (was crashing before)

Remaining tasks

  1. Review and merge the fix.

API changes

No changes.

CommentFileSizeAuthor
#9 3590259-9-mr19.patch740 bytesjoegraduate

Issue fork migmag-3590259

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kevinwlu created an issue. See original summary.

kevinwlu’s picture

Issue summary: View changes
kevinwlu’s picture

Issue summary: View changes
kevinwlu’s picture

Issue summary: View changes

kevinwlu changed the visibility of the branch 3590259-fatal-error-when to hidden.

kevinwlu’s picture

Issue summary: View changes
joegraduate’s picture

Version: 1.8.4 » 1.8.x-dev
Assigned: kevinwlu » Unassigned
Status: Active » Needs review
joegraduate’s picture

StatusFileSize
new740 bytes

Adding copy of current MR diff as patch file for composer.