Coming from #1879726: Should statistics be collected on every page?

Origin report by mondrake

Notice: Trying to get property of non-object in drupal_lookup_path() (line 77 of /..../includes/path.inc).

This is happening when serving a cached page, and you have specified page-based restrictions.

There is a drupal_get_path_alias() on line 147 of better_statistics.statistics.inc, which calls a drupal_lookup_path(), which in turns expects the global $language_url to be set - but with low bootstrap phase it looks like this is not defined, hence the notice.

...

Nothing broken AFAICS. I updated the module on a live site where I applied the following restrictions:
- cache: enabled
- roles: only anon users
- pages: all but an excluded path

Everything gets logged as expected, but any time a page is served from cache, the php notice gets logged in the watchdog.

And yes, the site is multilingual, albeit URL detection is not enabled.

I just gave a try at raising the bootstrap phase to DRUPAL_BOOTSTRAP_LANGUAGE in the hook_exit implementation - which takes away the notice, but unfortunately is very late in the page processing request and raises some 'headers already sent' warnings, which is definitely worse.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mondrake’s picture

Not sure if this is the right thing to do...

this patch checks if the global variable $language_url is set just before calling drupal_get_path_alias(), and if not initializes the language via drupal_language_initialize(). We're already at hook_exit here, and this hopefully "shouldn't" be creating issues with drupal_bootstrap().

If we were to raise to DRUPAL_BOOTSTRAP_LANGUAGE via drupal_boostrap(), that would also invoke _drupal_bootstrap_page_header() hence trying to open headers again (but here the cached page has already been sent I believe).

This seems to be working for me, I'll report back when I have more history.

mondrake’s picture

Status: Active » Needs review

Forgot to change status... :(

iamEAP’s picture

This seems fine to me. Let me know if you come across any side effects, otherwise I'm fine committing this.

mondrake’s picture

Fix in #1 works fine in my environment, no side effects. I am re-rolling here with a test as well.

Arguably, the test is much more complex than the fix itself :(, so please take a good look at it.

Cheers

iamEAP’s picture

iamEAP’s picture

Status: Needs review » Fixed

This looks good to me; the test may catch unrelated issues, but that's probably a good thing. Committed 0e9d65b.

Thanks, mondrake!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.