Currently, the sequence of module_enable() is as follows (once it is determined that the module needs to be installed):
- The module's main code file ("*.module") is loaded.
- The module's install file ("*.install") is loaded.
- The database is updated to reflect that the module is installed.
- The cache of which modules are enabled is cleared.
- The cache of which modules implement what hooks is cleared and rebuilt.
- The file registry ("system" table) is updated.
- The database schema cache is cleared.
- The theme registry is rebuilt.
- The module's schema is installed.
(The steps of largest significance to this issue are bolded.)
There are several problems with this approach:
- If the module fails to install, it's marked as already having been installed in the database, but without its schema. Other modules that depend on the module might install but have errors as soon as they call API exposed by the problematic module that relies on the schema.
- Any modules that alter the registry (like ctools) are free and clear to invoke hooks on the module being installed (for example, RDF) without realizing that the module's schema is not yet available. Or, more likely, a module like ctools will invoke normally innocuous hooks in other modules which, in turn, invoke hooks on the module being installed.
As a result of this issue, we have a problem with a distribution we're preparing that will inexplicably fail to install depending upon the order of the modules being installed. For example, if we install Feeds, which depends on CTools, then install RDF, the install fails.
Here's a sample stack:
405:_rdf_mapping_load(commerce_coupon,discount_coupon)
1101:rdf_entity_info_alter(Array,,,)
7682:drupal_alter(entity_info,Array)
170:entity_get_info()
533:_feeds_feeds_plugins()
686:feeds_feeds_plugins()
649:ctools_plugin_process(Array,feeds,feeds,modules/contrib/feeds)
264:ctools_plugin_load_hooks(Array)
33:ctools_get_plugins(feeds,plugins)
597:_ctools_registry_files_alter(Array,Array)
1101:ctools_registry_files_alter(Array,Array,,)
65:drupal_alter(registry_files,Array,Array)
3228:_registry_update()
452:registry_update()
1609:module_enable(Array,)
:_install_module_batch(rdf,RDF,Array)
284:call_user_func_array(_install_module_batch,Array)
161:_batch_process()
80:_batch_do()
449:_batch_page()
339:install_run_task(Array,Array)
77:install_run_tasks(Array)
26:install_drupal()This is Major because there's no good way around it at install time without directly manipulating the order that modules get installed. I'm tempted to say it's Critical because it can pop up without warning when installing modules on a live site in the wrong order, and requires a lot of debugging to nail down.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | drupal-2403535-module_hooks_available_before_install-6.patch | 1.07 KB | guypaddock |
Comments
Comment #1
guypaddock commentedAdding #2335387: RDF mapping table missing as related.
Comment #2
guypaddock commentedComment #3
guypaddock commentedHere's a patch that seems to resolve the issue locally. Although similar in concept to the one proposed in #1311820: Don't do a registry_update() before installing a module, I didn't move the call to rebuild the registry, I moved the loading of the module's own code until after the registry is rebuilt.
This should not have far-reaching side effects, but may affect modules that expect their own code to be available in hook_schema(). By the time that hook_install() and hook_enable() are called, the module code has been loaded. This also only affects calls to hook_schema() that result from calls to rebuild the registry (i.e. through ctools or the like).
Comment #4
guypaddock commentedSetting to NR.
Comment #6
guypaddock commentedTry this.
Comment #7
guypaddock commentedSetting to NR.
Comment #9
kingfisher64 commentedThis issue has been driving me mad. https://www.drupal.org/node/2335387 shows my attempts at solving this.
@GuyPaddock did you get round to solving this?
Many thanks
Comment #10
guypaddock commentedNo, sadly, this is a prickly area of core.
Comment #11
guypaddock commentedHave you tried this one?
https://www.drupal.org/node/1311820#comment-9581751
Comment #12
kingfisher64 commentedThanks GuyPaddock, I've just tried that patch along with the user patch, still no luck. Going to have to give up on this module, as I can't get it to work.
I'll try subprofile unless you have any other suggestions? Hate giving up but I'm not a dev to be able to fix it myself.
Comment #13
guypaddock commentedWe ended up removing RDF from our project since core's version isn't terribly useful and most of the pages on the site for this project are private.
The patch on comment #13 in #1311820: Don't do a registry_update() before installing a module worked for me in #2480297: During site install - PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'entityform_type' in entityform_entity_info() , though, which similarly was related to hook_entity_info() getting called on a module that's not yet done installing.
Comment #14
kingfisher64 commentedProgress at least. Removed rdf from dependencies list and applied module patch on #13 you referenced and https://www.drupal.org/node/2412003 for the user module (as it's a new site).
So no errors and getting to 100% now but it appears to hang for a very long time then says the server is reset.
I'm running 7.36. Do you have any other patches applied?
Thanks
Comment #15
guypaddock commentedOkay, so... this was working fine for us with Profile2, now all of a sudden it's not.
It also seems that Workflow doesn't install properly with this patch applied. I get a ton of errors on install.
Comment #16
gbangban commentedThe patch (https://www.drupal.org/files/issues/1311820-drupal-registry_update-13.patch) from https://www.drupal.org/node/1311820#comment-9581751 seems to fix this as well as updating to 7.43.
Any issues with closing out this ticket?