I've bumped my head over this one a few times now and I always tend to forget. If you're implementing hook_boot, the module cache (system table) needs to be rebuilt. You can do this by going to admin/build/module.
Why is this? hook_boot is called during the bootstrap like this:
/**
* Call all init or exit hooks without including all modules.
*
* @param $hook
* The name of the bootstrap hook we wish to invoke.
*/
function bootstrap_invoke_all($hook) {
foreach (module_list(TRUE, TRUE) as $module) {
drupal_load('module', $module);
module_invoke($module, $hook);
}
}
As you can see, module_list is called here with the second parameter set to TRUE. Looking at what this parameter means, gives us $bootstrap. Let's look at the (partial) implementation of the module_list function to see what it's used for:
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");
}
//...
}
We're filtering on bootstrap = 1 when selecting from the system table.
As you know or not know, this table only gets (re)built when the available modules are scanned. This happens when module_rebuild_cache is run. This is what gets done if you go to your modules page.
Comments
That explains the strange behaviour I had :)
Bumped on your post in my quest to find out how to switch theme for anonymous users in hook_boot() when cache is enabled...
Added to DrupalSightings.com
Post new comment