I have an issue disabling modules, I've searched but cannot find something useful:
- Developer A disable module and via composer remove it
- I pull his changes so i run composer install that remove the code, then drush cim to update configuration, but it complains that the module is missing while it's trying to delete its configurations.

What's the right way to do this? I can't import config before running composer install because along the uninstalled module there could be also new modules needed for the configuration import.

up vote 3 down vote accepted

You need two consecutive releases for stuff like that.

First release:

Your colleague uninstalls the module and commits the updated config. But he also needs to ensure that the module needs to get uninstalled via some hook_update_N before the config gets imported in everybody else's setup.

/**
 * Uninstall SOME_MODULE module.
 */
function MYMODULE_update_8001(&$sandbox) {

  \Drupal::service('module_installer')->uninstall(['SOME_MODULE']);
}

Second release:

The module can be removed via Composer.


Related:

Order of drush commands for automated deployment?

  • Thanks, everything's clear to me! Thanks also for the related question, very intresting! – Francesco Oct 19 at 10:01
  • You actually do not require an update hook just to uninstall the module. The configuration management in D8 could be used for it. Added an alternative answer built on top of your. cc @Francesco – AjitS Oct 19 at 11:06

Adding an alternative solution to @leymannx - you will still need two releases. This is taking into consideration your mention of drush cim

First release:

  1. Uninstall the module drush pmu module_name
  2. Export the configuration.
  3. Commit, push, and release.
  4. Deploy and execute drush cim. That should uninstall the module.

A hacky way to uninstall is directly editing the core.extension.yml, remove the complete entry of the module from under the module: key, and executing drush cim. NOTE: Use this hacky way only when you are sure that the module doesn't export any configuration. Else, there would be an exception thrown.

Second release:

Removing module from composer.

  • 1
    Yeah, but there may be other config related to that module. If I remember it right, it's not safe to just edit core.extension.yml. The uninstallation routine needs to be triggered, to remove all other related config as well. And that needs to happen before drush cim via an update hook. – leymannx Oct 19 at 11:33
  • Thanks, it seems to me that the accepted answer is more "safe" but this could be helpful. While developing without an actual release online should be ok to speed up and avoid a lot of code, and errors can be handled easily. – Francesco Oct 19 at 12:35
  • @leymannx You are right! I didn't consider that. I did update the question on when to use the hacky way. The normal way of 4 steps mentioned in the answer should work well without the hacky way. – AjitS Oct 21 at 7:22

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.