Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
As of #2140511: Configuration file name collisions silently ignored for default configuration, ModuleInstaller::install
throws a PreExistingConfigException
exception when a module is installed that provides configuration that already exists on the site.
This change presents a problem for packages because the usual workflow is:
- Configure site.
- Create packages.
- Enable packages on site.
- Continue to edit packages.
This workflow will break on step 3, since the configuration already exists on the site.
Proposed resolution
Possibly, break package creation into two steps. First, generate an empty package. Then, once enabled, add configuration.
Comments
Comment #1
mpotter CreditAttribution: mpotter commentedThis definitely seems like a blocking issue. Right now I can create packages and put them into my profile. But the package modules don't/can't get enabled on my dev site because of the core issue raised above.
The core issue was closed and instead they just added error messages telling users why a module wasn't enabled. The fact that there doesn't seem to be a way to enable the module anyway and just ignore the config conflict seems annoying.
I will try the proposed resolution, but it seems that only helps with the initial problem. What happens when we want to move a "package" to another site and install it outside of an install profile?
Given we have the config_update module to potentially reload the config from the module, we really need a way to install a module with config outside of config_packager somehow. In the above issue they refer to the exception of allowing profiles to override existing config, so maybe we need to find out how this exception is implemented?
Comment #2
mpotter CreditAttribution: mpotter commentedI wonder if we should add a way to handle "feature enable/disable" that is different from "module enable/disable". Since you can't enable a module that contains config already in the active store, Features could add drush commands and a UI around enabling/disabling packages. Then we could potentially fix this by:
1) Find all conflicting config and move to a separate folder
2) Install the module
3) Move the conflicting config back into config directory
4) Optionally run config_update to "revert" the config
I hate playing these kind of games with folder names, but unless D8 core does something to get around the exception error I'm not sure what else to do.
Comment #3
nedjoLikely the way to handle this is something similar to what I've done in Configuration Share:
config.installer
service. See the section "Defining a service" in the API documentation andConfigShareServiceProvider
.ConfigInstaller::listDefaultConfigToInstall()
to provide a version that excludes config provided by features-type modules if it already exists on the site. (Of course, this would require a means of identifying features-type modules.)ConfigShareConfigInstaller::listDefaultConfigToInstall()
overrides this method for a different purpose: to add configuration provided by a common store, in order to facilitate interoperability among features and distros.Comment #4
mpotter CreditAttribution: mpotter commentedI think we will be able to identify "features-type modules" because I was going to change the info.yml file from 'config_devel' to 'features' since we don't actually want config_devel to manage this config. So I'll already have a method to return a list of "features modules".
I'll take a look at the custom config service. That seems like a cleaner route. I think it's ok for this installer service to be in config_packager (Features) since it only is an issue when initially creating the package.
Comment #5
nedjoComment #6
mpotter CreditAttribution: mpotter commentedDid something similar to #3 but found the findPreExistingConfiguration() function that could also be easily overridden. We grab the module's info.yml file and check for the "features" key to allow a feature package to be installed.
Committed to 950c9cc
Comment #7
nedjoSounds good. I'm not seeing the commit. Maybe not pushed yet?
Comment #9
mpotter CreditAttribution: mpotter commentedNot sure what took it so long to appear, but there it is: http://cgit.drupalcode.org/features/commit/?id=950c9cc
Comment #10
nedjoNice!
Minor nits:
Code comments should be full sentences.
Leftover copied from config_share. Ditto in FeaturesServiceProvider.php.
Comment #11
nedjoSince a similar test is appearing in multiple places, it should be pulled into a helper public method, probably in FeaturesManagerInterface.
Comment #13
mpotter CreditAttribution: mpotter commentedMade the changes from #11 along with some other refactoring to make this even cleaner. Thanks for the review and let me know what else you find.
Committed in 09c596a.
Comment #14
mpotter CreditAttribution: mpotter commented