Problem discovered during implementation of following issue #2899669: Test modules if they are reinstallable..

Problem/Motivation

When module is uninstalled it should clean-up configurations. Because after uninstall -> install is not possible because configuration already exists.

Proposed resolution

There are few ways to handle this:

  1. Add uninstall hook that will remove configuraitons provided with installation of module.
  2. Define configuration with module enforced depndency
  3. Move configuraitons into optional configurations and not install
CommentFileSizeAuthor
#5 Snap.png32 KBzalak.addweb
#3 2901581_3.patch1.02 KBmtodor
#2 2901581_2.patch1.63 KBmtodor

Comments

mtodor created an issue. See original summary.

mtodor’s picture

StatusFileSize
new1.63 KB

Here is solution with hook_uninstall().

mtodor’s picture

Status: Active » Needs review
StatusFileSize
new1.02 KB

Just uploading new patch without renaming of the configuration file, since that's addressed in #2860803: Cleanup default configuration.

mtodor’s picture

Issue summary: View changes
zalak.addweb’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new32 KB

@mtodor, Thanks for providing steps & patch, both help me to check & Perform RTBC. It works well as I checked it with simplytest.me. PFA

quietcorn’s picture

So what is the process by which this can be uninstalled? I'm running into an issue where it wasn't working because I enabled the module before installing the theme, so I tried uninstalling it, and I got caught by this problem.

I found some information about how to remove a configuration. I ran this with the drush php console:

>>> Drupal::configFactory()->getEditable('image.style.amp_metadata_logo_600x60')->delete();

resulting in this message:

=> Drupal\Core\Config\Config {#7443}

Then I tried re-enabling amp, and got this response:

Drush command terminated abnormally due to an unrecoverable error.                                                                                      [error]
Error: Cannot redeclare amp_update_8003() (previously declared in
/Applications/MAMP/htdocs/drushlm8target/drushinstall1/modules/contrib/amp/amp.install:92) in
/Applications/MAMP/htdocs/drushlm8target/drushinstall1/modules/contrib/amp/amp.install, line 118

Not sure where to go now. I do need AMP to work on my site. Any advice you might have would be really appreciated.

karens’s picture

This should not be a problem after https://cgit.drupalcode.org/amp/commit/?id=dae5667. That commit is not in a packaged release but only on the development branch. If you originally installed the module from the packaged release or from a development release before that commit you'll have these problems uninstalling and reinstalling. For any installation after that commit things should be fine. Note that this code needed to be in the module when you installed it, so you'll still have problems on older installations and you'd need something like the above to remove the old config.

This problem is fixed in the latest development code.

karens’s picture

Status: Reviewed & tested by the community » Needs work

Changing this to needs work just to make it clear that this is probably not needed as a patch to the module, since the module has already been fixed. Just need to confirm that there isn't any need for more than that.

karens’s picture

Status: Needs work » Fixed

This patch is not needed, there is now a new release with the fix.

Status: Fixed » Closed (fixed)

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