Problem/Motivation
When modules are being installed during configuration sync, \Drupal::service('config.installer')->isSyncing() returns FALSE in hook_module_preinstall() implementations. This is because the kernel is updated and the container is rebuilt just prior to the preinstall hooks being invoked. The config installer sync status is not set back to TRUE until later.
Proposed resolution
Restore state of ConfigInstaller, including whether it is syncing and its source storage in \Drupal\Core\Extension\ModuleInstaller::updateKernel().
Pass ConfigInstaller::isSyncing value to hook_module_preinstall() and hook_module_preuninstall implementations.
Remaining tasks
(reviews needed, tests to be written or run, documentation to be written, etc.)
API changes
See change record: hook_module_preinstall() and hook_module_preuninstall() now have a second argument $is_syncing
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3103962
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:
- 3103962-configinstallerissyncing-is-not
changes, plain diff MR !5270
Comments
Comment #2
godotislateComment #3
godotislateMessed up diff with original patch. Trying again.
Comment #4
godotislateHere's a failing test.
Comment #5
godotislatePatch with tests.
Comment #6
godotislateComment #7
xjmSince this fix would involve a behavior change, it's best done in a minor release. Moving to 9.1.x. Thanks!
Comment #12
ranjith_kumar_k_u commentedRerolled #5 for 9.5
Comment #17
godotislateCreated MR against 11.x
Comment #19
smustgrave commentedRebased to run test-only feature
Hiding files for clarity.
Issue summary seems clear about what is being fixed and matches the solution in the MR.
LGTM!
Comment #20
xjmComment #21
larowlanIssue credits
Left some questions on the MR, tl;dr I think hook_module_preuninstall has the same issue and wonder if perhaps we should be doing the fix inside ::updateKernel so it resolves both issues at once.
Comment #22
alexpott@larowlan excellent point about uninstall. Install and uninstall should be mirrors.
I'm slightly dubious about the use-case here because what are you doing in pre-install - really shouldn't be doing anything permanent - so whatever is happening probably should happen regardless of whether we are syncing - but hey workspaces does interesting stuff here but it is inconsistent so +1 to fixing.
I think we should also consider adding is_syncing to the hook signature to anyone who implements hook_module_preinstall() has to consider the config syncing case.
Comment #23
godotislateI agree use cases are pretty obscure, and I'm having trouble recalling exactly how it was I ran into it four years ago. I believe that I was working on a project that had an install profile that used Config Rewrite (https://www.drupal.org/project/config_rewrite). That module has an hook_module_preinstall() implementation that I wanted to prevent from happening when installing from existing configuration. Though it looks like between then and now they found a different way to do that detection.
Comment #24
godotislateAddressed review comment to restore state of config installer in ::updateKernel.
Added $is_syncing value as second parameter to hook_module_preinstall() and hook_module_preuninstall implementations.
Updated tests and rebased.
Added CR and updated IS.
Comment #25
alexpott@godotislate - nice work - one tiny nit in a kinda out-of-scope change and this will be rtbc.
Comment #26
godotislateApplied suggested change and moved to RTBC per last comment.
Comment #27
alexpottCommitted ba827d4 and pushed to 11.x. Thanks!