I am occasionally getting the following error:

Fatal error: Call to undefined function drupal_get_path() in /path/to/better_statistics/better_statistics.module on line 181

Seems like there's no harm in replacing the drupal_get_path with a dirname(__FILE__).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

iamEAP’s picture

And actually, after trying that, it fired another call to undefined function, this time on drupal_get_schema_unprocessed. Looks like we need to manually include common.inc in better_statistics_exit().

iamEAP’s picture

Priority: Normal » Major

Looks like this happens only when a page is served from cache. Bumping to major.

We should also add a test for this.

mondrake’s picture

+1 I also found my error_log full of this. All cached pages served to anonymous users.

Cheers

iamEAP’s picture

Status: Active » Needs review
FileSize
1.31 KB

No tests, but I'm using this on a production site.

Another workaround, I believe, is to just save the statistics configuration form.

mondrake’s picture

Status: Needs review » Needs work

Currently testing on a site. The patch itself seems OK. The problem I currently have is with caching overall. It seems like modules are not 'loaded' when serving a cached page. So I have a problem in the integration I wrote for Browscap. The statistics.api works, but a sub-function (called by the callback) which resides in the module, is not available, so kicking a 'Call to undefined function browscap_get_browser()' in the error_log (I am not sure if the page was served anyway, or the error presented to the user as well).

I'll be back when I have more. Most probably nothing for you to do in code, but some development guidelines for documentation to be added to cope with caching.

Makes sense to you?

iamEAP’s picture

Status: Needs work » Needs review

Hi, Mondrake. I believe I understand; I've created a separate issue here: #1879512: API - Dealing with statistics data collection on cached page requests Let me know there if I'm completely off base.

In the meantime, let me know how the patch above works for you.

Think I'd like to do another point release once this, the issue I just mentioned, and drush integration are done.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

I made progress vs. my issue in #5: Browscap now OK, but my other module using statistics API, ip_geoloc, now shows the same problem).

This means I believe that the patch in #4 works fine as long as no other modules are engaged in a cached page request - for which I will follow on in #1879512: API - Dealing with statistics data collection on cached page requests that makes the exact point.

All this to say RTBC :)

iamEAP’s picture

Status: Reviewed & tested by the community » Fixed

Thanks as always for your participation, mondrake!

http://drupalcode.org/project/better_statistics.git/commit/e88ba2b

mondrake’s picture

Status: Fixed » Active

Hmmm - sorry to reopen.

Now I am getting the following error:

Warning: Invalid argument supplied for foreach() in better_statistics_get_default_fields() (line 178 of /..../sites/all/modules/better_statistics/better_statistics.module).

when a page is served from cache, with modules integrated through the API.

In fact I believe the problem is in line 173-4

    module_load_install('statistics');
    $schema = module_invoke('statistics', 'schema');

module_load_install() calls module_load_include() that calls drupal_get_path(). If this last is not defined, statistics.install won't be loaded and the schema result empty - leading to the error above.

Would it make sense to include statistics.install directly instead, like (not tested yet, just thinking aloud :)) :

    include_once DRUPAL_ROOT . '/includes/install.inc';
    require_once DRUPAL_ROOT . '/modules/statistics/statistics.install';
    $schema = module_invoke('statistics', 'schema');

cheers

mondrake’s picture

Status: Active » Needs review
FileSize
694 bytes

Yep, solution in #9 worked fine for me, so here's the patch for review

iamEAP’s picture

Status: Needs review » Needs work

Thanks for the patch, Mondrake.

Seems good, but it's definitely apparent that we need to add tests to ensure we don't get these errors on pages served from cache.

I likely will not have time to get to this until at least the weekend, so feel free to take a stab at a test.

mondrake’s picture

Not really my playground :)

I'll be happy to review yours...

iamEAP’s picture

Alright. Here's two patches. One's test only, the other is test and real patch. Test only should fail, the full patch should pass.

I made one modification to your patch in #10, mondrake. The call to require install.inc isn't necessary.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Works fine. Thanks.

iamEAP’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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