Fatal error: Call to undefined function drupal_get_path() in /home/members/icirr/sites/icirr.org/web/sites/icirr.org/modules/opencalais/arc_rdf/arc_rdf.module on line 52

When I have normal caching enabled, this error occurs when browsing as the anonymous user. Without caching enabled, this does not happen.

I have Localizer module enabled.

This error happens frequently but not every time. Sometimes I can reload a page that loaded fine and get the error.

Needless to say, OpenCalais works fine when I'm logged in or when caching is disabled.

Comments

Anonymous’s picture

Title: Normal caching with OpenCalais module causes fatal error » Localizer + normal caching + OpenCalais causes fatal error
Project: OpenCalais » Localizer

After poking around in Localizer, I suspect this is a localizer issue instead.

Anonymous’s picture

Title: Localizer + normal caching + OpenCalais causes fatal error » normal caching + OpenCalais causes fatal error
Project: Localizer » OpenCalais

Ok. So I removed localizer entirely from my site, and I still get the error.

That tells me it's not a localizer problem.

I've got a cold, so forgive me for filing the issue if this is a time waster. I probably shouldn't file issues while medicated!

Anonymous’s picture

Category: support » bug
Priority: Normal » Critical

I found the problem. All implementations of hook_init in the Calais modules call functions that aren't loaded when pages are cached. See #45190: drupal_get_path() call in category_init() fails for cached pages.

I found that content.module's implementation of hook_init wraps code in this condition:

function content_init() {
  // ensure we are not serving a cached page
  if (function_exists('drupal_set_content')) {
    // we don't do this in hook_menu to ensure the files are already included when
    // views_menu is executed
    if (module_exists('views')) {
      include_once('./'. drupal_get_path('module', 'content') .'/content_views.inc');
    }
    if (module_exists('panels')) {
      include_once('./'. drupal_get_path('module', 'content') .'/content_panels.inc');
    }
    // according to http://drupal.org/node/60526, this should not go in hook_menu
    if (module_exists('pathauto')) {
      include_once('./'. drupal_get_path('module', 'content') .'/content_pathauto.inc');
    }
  }
}

Localizer also checks:

function localizer_init() {
  $scriptname = basename($_SERVER['SCRIPT_NAME']);
  if($scriptname!='index.php') return;
  if(function_exists('drupal_get_path')) {
    _localizer_change_language();
    if(localizer_is_front_page() && localizer_exists_localized_content($_GET['q'], localizer_get_language())) {
      $path = localizer_get_localized_path($_GET['q'], localizer_get_language());
      $apath = drupal_lookup_path('source', $path);
      $path = $apath? $apath : $path;
      $_GET['q'] = $path;
    }
  }
}

The following Calais hooks will need attention:

calais_api_init
calais_init
arc_rdf_init

I'd submit a patch, but caching and bootstrapping is over my head.

febbraro’s picture

Assigned: Unassigned » febbraro

I see the problem, however, for some reason I have not been able to duplicate it so I wont know if I have fixed it. Do any of you have a quick checklist of steps so that I can reproduce it? Logged in or as anonymous? On view? Calais Tab view? Edit? Save?

Thanks for helping me narrow in on it.

steve hanson’s picture

I don't know of any predictable way to make this happen - in general, you just let the site aggregate for a while, and then suddenly the site dies.

I have a test site I could run it on to see if it is fixed - is there a version available where you've made the fix?

Anonymous’s picture

The problem happens when normal caching is enabled. It's an inevitable result of using the drupal_get_path in hook_init without checking first that the function is available. It happens every time you attempt to load a page while not logged in and normal caching is active.

febbraro’s picture

Status: Active » Fixed

Fix committed to CVS. New release coming soon.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

doublejosh’s picture

Cool, had the same set of issues and traced it to cached content not having access to the drupal_get_path().

Noticed this type of problem has been solved in other modules by placing loading the unit in the menu function... but that appears to only have value because of the if($may_cache) ex... http://drupal.org/node/200395#comment-680563

I tried turning off the three calls to drupal_get_path() in question (arc_rdf.module line 52, calais_api.module line 18, and calais.module line 18) by wrapping them in a test on if($may_cache), but that wasn't enough... I'd need to test for function_exisits(drupal_get_path)... and I don't feel that's exactly protecting the module from caching mode properly.

For now turning off cache until I see a new revision. Let me know if I can help.

I, for one, do need Calais available for unregistered users... for aggregating feeds on cron.

The calais caching issue also lives here: http://drupal.org/node/286750