Hi,

I'm playing with migrations from D7 to D8 and I've found that, when you register a module with a migration, if you disable it, next time you enable the module gets stuck on this:

[vagrant@devbox] /[...]/default $ drush en progweb_migration -y
PHP Warning:  Module 'imagick' already loaded in Unknown on line 0
PHP Warning:  Module 'imagick' already loaded in Unknown on line 0
The following extensions will be enabled: progweb_migration
Do you really want to continue? (y/n): y
exception 'Drupal\Core\Config\PreExistingConfigException' with message 'Configuration objects[error]
(migrate.migration.custom_user) provided by progweb_migration already exist in active
configuration' in /www/drupal8/core/lib/Drupal/Core/Config/PreExistingConfigException.php:70
Stack trace:
#0 /www/drupal8/core/lib/Drupal/Core/Extension/ModuleInstaller.php(162):
Drupal\Core\Config\PreExistingConfigException::create('progweb_migrati...', Array)
#1 /opt/drush7/vendor/drush/drush/commands/core/drupal/environment.inc(129):
Drupal\Core\Extension\ModuleInstaller->install(Array, true)
#2 /opt/drush7/vendor/drush/drush/commands/core/drupal/environment.inc(196):
drush_module_install(Array)
#3 /opt/drush7/vendor/drush/drush/commands/pm/pm.drush.inc(1120): drush_module_enable(Array)
#4 [internal function]: drush_pm_enable('progweb_migrati...')
#5 /opt/drush7/vendor/drush/drush/includes/command.inc(359):
call_user_func_array('drush_pm_enable', Array)
#6 /opt/drush7/vendor/drush/drush/includes/command.inc(210): _drush_invoke_hooks(Array,
Array)
#7 [internal function]: drush_command('progweb_migrati...')
#8 /opt/drush7/vendor/drush/drush/includes/command.inc(178):
call_user_func_array('drush_command', Array)
#9 /opt/drush7/vendor/drush/drush/lib/Drush/Boot/DrupalBoot.php(46): drush_dispatch(Array)
#10 /opt/drush7/vendor/drush/drush/drush.php(76):
Drush\Boot\DrupalBoot->bootstrap_and_dispatch()
#11 /opt/drush7/vendor/drush/drush/drush.php(16): drush_main()
#12 {main}

It's like the migration is being registered but not de-registered. In D7 there is a method for that, but no luck so far trying in D8:

function progweb_migration_enable() {
  Migration::registerMigration('custom_user');
  Migration::registerMigration('custom_blog');

  Migration::registerMigration('ProgwebBlog');
  Migration::registerMigration('ProgwebUser');
}

function progweb_migration_disable() {
  Migration::deregisterMigration('custom_user');
  Migration::registerMigration('custom_blog');

  Migration::deregisterMigration('ProgwebBlog');
  Migration::registerMigration('ProgwebUser');

}

Is it a bug? Anywhere I could help?

Thank you.

Comments

bzrudi71’s picture

I think the trick is to add hook_uninstall to your your_module.module file.

function your_module_uninstall() {
  db_query("DELETE FROM {config} WHERE name LIKE 'migrate.migration.your_module%'");
  drupal_flush_all_caches();
}
alexmoreno’s picture

Yep, that fixed the error.

Shouldn't that be abstracted in some method like MIGRATE::deregister('my_migration_config'); as it looks it was in D7 ?

It happens also for the d6 migration configs.

mikeryan’s picture

The D8 migration framework does not (yet) have the concept of registering/deregistering migrations - but I agree it should: #2202475: Registering/instantiating migrations.

kevinquillen’s picture

This just got me - came here looking for deregister methods. Deleting it out of the config table got around this.

mikeryan’s picture

Status: Active » Closed (duplicate)
Related issues: +#2460529: Migrations need to use the configuration entity dependency system

#2460529: Migrations need to use the configuration entity dependency system should address removing ("deregistering") migrations on the uninstall of their implementing module - you may need to add some dependency configuration/code, hopefully that issue will end up with clear documentation on this.