It is expected that module hook_update_N() implementations should not use the module's own APIs, but that is not for the module's hook_schema(), hook_install() or hook_enable() implementations.
Drupal 7's module_enable()'s workflow is roughly as follows:
- Load mymodule.module file.
- Load mymodule.install file.
- Update the {system} table to mark the module as being enabled.
- Reset the cached list of system files.
- Clear the cached list of module files.
- Clear the cached list of hook implementations.
- Reload the system registry to include all files identified in the previous steps.
- Clear the cached schema.
- Clear the entity info cache.
- Install the new module's schema.
- Update the module's schema_revision value to the numerically highest hook_update_N() implementation.
- Run the module's hook_install() implementation, if present.
- Run the module's hook_enable() implementation, if present.
It's worth noting that step 7 causes any implementations of hook_registry_files_alter() to execute, which can lead to unexpected problems, like Media module not installing or the same with Styles module.
What I would recommend is changing the installation process to not load the module file, rely on the hook_install() to instead deal with any custom logic on its own and only run registry_update() after the module has been properly installed.
Comment | File | Size | Author |
---|---|---|---|
#13 | 1311820-drupal-registry_update-13.patch | 923 bytes | hefox |
#10 | patch-to-module_enable-for-profile-installation-1311820.patch | 1.55 KB | azovsky |
Comments
Comment #1
DamienMcKennaI created a related CTools issue: #1311824: ctools_registry_files_alter() causes problems during installation profiles
Comment #2
exratione CreditAttribution: exratione commentedHere's a patch for module_enable() (in 7.10) that works for my profile installation situation, which had issues with both registry_update() and drupal_get_schema() for much the same reasons. Your mileage may vary, of course.
Comment #3
nedjoIndeed there are many issues out there that relate to the problem of a module's methods being called before it is fully installed.
However, updating the registry before a module is enabled seems to be by design and required. Modules frequently use their own methods at install time. For this to work, their own code needs to be available. Therefore the registry needs to be updated before their install hooks are called.
The solution to this seems to be that modules need to conditionally skip certain API calls at install time (when Drupal or a module or theme is being installed). We may need a convenience method equivalent to
drupal_installation_attempted()
but that returns TRUE also when a module or theme is being installed.Comment #3.0
nedjoCorrect Media module issue URL.
Comment #4
rlmumfordI agree, the .module file should not be included until the module's install function has run. Any other functions could still be used if they were in other includes that could then be embedded.
Comment #5
rlmumfordI think this bug should be marked as critical as currently it stops lots of entity providing modules from being used in install profiles. We should either document that modules need to check whether tables exist in some functions OR fix this in drupal core.
Comment #6
hefox CreditAttribution: hefox commentedComment #7
rlmumfordThis has come up again. #2313235: Fails to complete installation
Comment #8
GuyPaddock CreditAttribution: GuyPaddock commentedLooks like the issue I just filed is eerily similar:
#2403535: module_enable() exposes module hooks before the module's schema is installed
Comment #9
GuyPaddock CreditAttribution: GuyPaddock commentedComment #10
azovsky CreditAttribution: azovsky commentedClean the patch file (can apply for D7.34 from now).
Comment #11
azovsky CreditAttribution: azovsky commentedComment #13
hefox CreditAttribution: hefox commentedHere's a patch that purely moves register_update. What is the purpose of also moving drupal_get_schema?
Comment #14
GuyPaddock CreditAttribution: GuyPaddock commentedAdding more related issues.
Comment #15
GuyPaddock CreditAttribution: GuyPaddock commentedPruning dupes.
Comment #16
GuyPaddock CreditAttribution: GuyPaddock commented#13 works for me! Sooooo glad to finally have a solution.
Comment #17
Dane Powell CreditAttribution: Dane Powell at Acquia commented#13 fixes a number of entity-related modules breaking during installation with install profiles (such as Paragraphs: #2412747: Fatal error: Class 'ParagraphsItemMetadataController' not found). I haven't noticed any side effects.
Comment #18
grom358 CreditAttribution: grom358 commentedI also can confirm this worked in resolving an issue with paragraphs as per #17
Comment #19
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commented@nedjo's comment in #3 looks valid to me and has not been addressed. We shouldn't break modules that are currently using their own API in hook_install()...
Because of that, I'm not sure this is a bug core can or should fix, but perhaps at least it can do something (as @nedjo suggested) to make sure that contrib modules have an easy way to distinguish between a fully-installed module and one that is still in the process of being installed (if that doesn't already exist).
Comment #20
gbangban CreditAttribution: gbangban commentedLooks like this should be closed out. The patch is #13 is already in core 7.43.
Comment #21
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedNo it isn't: http://cgit.drupalcode.org/drupal/tree/includes/module.inc?h=7.43#n464
Comment #22
HLopes CreditAttribution: HLopes commentedAn implementation of hook_module_implements_alter removing the offending hook if the table doesn't exist seems to work as well.
For paragraphs (in my case) it would be something like
Comment #23
stephencamilo CreditAttribution: stephencamilo as a volunteer commentedComment #24
hestenetReset issue status.