i tried to upgrade "globalredirect" module to D6 and changed the hook_init to hook_boot, but hook_boot seems not fire at all. Simply add a _book hook to *any* module and try to add a watchdog entry, drupal_set_message, print "test" or a header() with redirect and nothing will happen at all!

Therefor it seems like hook_boot isn't working at all.

CommentFileSizeAuthor
#16 bootstrap_28.patch851 byteshass
#3 hook_boot.patch673 byteschx
#1 drupal_boot.patch559 bytesChrisKennedy
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ChrisKennedy’s picture

Title: hook_boot never executed » Fix hook_boot
Status: Active » Needs review
FileSize
559 bytes

Well, hook_boot() is currently only run if serving a normally cached page. Attached is a patch to run it on a full bootstrap also. Do we want it to run under aggressive caching?

ChrisKennedy’s picture

While researching this issue I also noticed that hook_boot never got added to http://api.drupal.org/api/group/hooks/6 and the hook_init documentation was not updated to explain that it's only for non-cached pages.

chx’s picture

FileSize
673 bytes

Funny thing is, hook_init had the same probs in D5. But your soluition is not right, boot should fire sooner.

hass’s picture

Chris: hook_boot should run like hook_init in D5. This means hook_boot will not fire in aggressive caching mode.

hass’s picture

Status: Needs review » Needs work

@chx: now, boot fires, but the function_exists('drupal_get_path_alias') gives "false"... and path lookup doesn't work in this level. If this will be the final patch i need to duplicate much Drupal Core function in the module. This maybe faster - but not very cool from the api side. Isn't there a better way? e.g. fire at DRUPAL_BOOTSTRAP_FULL, when every function is accessible?

hass’s picture

Additional if someone needs the language in this boot stage he cannot access this... it fires later, too

hass’s picture

Another maybe (?) bad idea with the current patch could be a require_once in global redirect...

function globalredirect_boot() {

  require_once './includes/path.inc';
  require_once './includes/common.inc';
  if (isset($_REQUEST['q']) && function_exists('drupal_get_path_alias') && !isset($_REQUEST['destination'])) {
    ...
  }
}
hass’s picture

major correction... i need to rebuild the complete DRUPAL_BOOTSTRAP_PATH in global_redirect module.


function globalredirect_boot() {
  // DRUPAL_BOOTSTRAP_PATH hasn't fired yet, but we need to do the same
  require_once './includes/path.inc';
  // Initialize $_GET['q'] prior to loading modules and invoking hook_init().
  drupal_init_path();
  require_once './includes/common.inc';

  if (isset($_REQUEST['q']) && function_exists('drupal_get_path_alias') && !isset($_REQUEST['destination'])) {

Gábor Hojtsy’s picture

Title: Fix hook_boot » hook_boot only invoked on "normal cached" page views, not on uncached page views

Yeah, I asked people to update the docs, there is still an open issue about it. Also, hass you should rethink whether you really should use hook_boot and not hook_init.

hass’s picture

Well, i think you are talking about my case http://drupal.org/node/161136.

I thought about moving to hook_init, but this hook doesn't fire on cached pages - isn't it? But global redirect need to run earlier and every time, while we must redirect for e.g. from "node/1" to the appropriate url alias - if one exists. This redirect need to be invoked for cached and non cached pages and this requires hook_boot as i understand :-(((.

Aside it would be a great deal if this small piece of code (global redirect) will be integrated into core to get rid of duplicate content without any extra modules... so we don't need to care of all the above problem at all.

Gábor Hojtsy’s picture

Hass, the whole point of caching is not to load/call a lot of functionality in the page! So it is a feature if code is not run there. And the other point of caching is that one needs to decide early, so the cached requests are very light. It does not seem there is a clean way for you.

chx’s picture

Status: Needs work » Needs review

Hass, if you need more stuff then just issue drupal_bootstrap codes to more advanced levels, like DRUPAL_BOOTSTRAP_PATH or _FULL .

Gábor Hojtsy’s picture

Status: Needs review » Fixed

OK, the hook_boot call moving is done, comitted. Thanks. (Please document in the update docs! I know we have some issue open for this, so I am not leaving this one open).

hass’s picture

Title: hook_boot only invoked on "normal cached" page views, not on uncached page views » hook_init only invoked on "normal cached" page views, not on uncached page views
Version: 6.x-dev » 5.x-dev
Status: Fixed » Active

I'm reopening this for a D5 backport, while chx found this bug exists in D5, too.

ChrisKennedy’s picture

Interesting... if true it's very strange that no one noticed this in D5.

hass’s picture

Status: Active » Needs review
FileSize
851 bytes

D5 patch attached

drumm’s picture

I am hesitant to move around hook calling in Drupal 5.x, which is in maintenance mode. Can anyone think of any way this might negatively affect modules which currently use hook_init()?

hass’s picture

Well, i think it changes some important things and will break some modules like global_redirect. I'm not sure if the patch is correct, so please review carefully. And we don't have a hook_boot... maybe it's better to stay as is... i change this only after chx said this problem is inside D5, too. not sure if this is fixed by the patch correctly, while i'm not so deep inside bootstrap part.

moshe weitzman’s picture

Status: Needs review » Fixed

i would wait for someone to strongly care before changing D5.

Anonymous’s picture

Status: Fixed » Closed (fixed)
gpk’s picture

Title: hook_init only invoked on "normal cached" page views, not on uncached page views » hook_boot only invoked on "normal cached" page views, not on uncached page views
Version: 5.x-dev » 6.x-dev

For the record, in 5.x hook_init() *is* invoked on uncached page views, in http://api.drupal.org/api/function/_drupal_bootstrap_full/5.

The difference for hook_init() as far as cached vs. uncached page views is that on an uncached page view the init hook is invoked right at the end of the bootstrap (so Drupal is fully loaded), whereas for a cached page view it is invoked during DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE phase, so most of Drupal has not been loaded yet.

This is why hook_init() was split into hook_boot() [invoked during DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE *for both cached and uncached page views*] and hook_init() [invoked at end of bootstrap, uncached page views only], in 6.x.

Resetting title and version.