module_implements() cache can be polluted by module_invoke_all() being called (in)directly prior to full bootstrap completion

Created on 19 June 2009, over 15 years ago
Updated 18 July 2024, 6 months ago

Problem/Motivation

there seem to be several cases where the module_implements() cache is polluted with incomplete info:

Proposed resolution

clear the static cache at the end of the full bootstrap and prevent the persistent cache from being written to prior to full bootstrap completion

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

And there are different opinions on how to solve it:

  1. Just document "you can't do this"
  2. #578044: move module_invoke_all() out of the reach of hook_boot() (though I'm not sure if this fixes the 2nd point)
  3. Throwing an exception when you do this (#10 / Damien Tournoud)
  4. previous + find a way then to be able to add hooks to the list of bootstrap hooks (#11 / Jose Reyero)

In the meantime, the patch uploaded in #14 fixes just the caching of incomplete info.

Original issue report

I can't understand the logic of module_implements() function.

Look on definition:

/**
 * @param $hook
 *   The name of the hook (e.g. "help" or "menu"). */
...
function module_implements($hook, $sort = FALSE, $refresh = FALSE) {
...
  if (!isset($implementations[$hook])) {
    $implementations[$hook] = array();
    $list = module_list(FALSE, TRUE, $sort); // second param is $bootstrap = TRUE
    foreach ($list as $module) {
      if (module_hook($module, $hook)) {
        $implementations[$hook][] = $module;
      }
    }
  }
/**
...
 * @param $bootstrap
 *   Whether to return the reduced set of modules loaded in "bootstrap mode"
 *   for cached pages. See bootstrap.inc. */
...
function module_list($refresh = FALSE, $bootstrap = TRUE, $sort = FALSE, $fixed_list = NULL) {
...
      if ($bootstrap) {
        $result = db_query("SELECT name, filename, throttle FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, filename ASC");
      }
...
/**
 * Define the critical hooks that force modules to always be loaded.
 */
function bootstrap_hooks() {
  return array('boot', 'exit');
}


1. I'm calling i.e. module_implements('help') expecting list of all modules that implement that hook
2. module_implements calling module_list with $bootstrap param = TRUE?
$list = module_list(FALSE, TRUE, $sort); // second param is $bootstrap = TRUE
3. So instead of receiving all modules with hook_help, I'm getting modules with this hook only which are registered as $bootstrap only

It's also related to: #222109: module_list() should be rewritten as 2 functions: module_list() and module_list_bootstrap()

🐛 Bug report
Status

RTBC

Version

7.0 ⚰️

Component
Base 

Last updated about 2 hours ago

Created by

🇬🇧United Kingdom kenorb

Live updates comments and jobs are added and updated live.
  • Needs framework manager review

    It is used to alert the framework manager core committer(s) that an issue significantly impacts (or has the potential to impact) multiple subsystems or represents a significant change or addition in architecture or public APIs, and their signoff is needed (see the governance policy draft for more information). If an issue significantly impacts only one subsystem, use Needs subsystem maintainer review instead, and make sure the issue component is set to the correct subsystem.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024