Call to undefined function drupal_get_path()

LoongFei - July 5, 2007 - 22:12
Project:Content Blocker
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:nedjo
Status:closed
Description

Using Drupal 5.1 here.

I was doing some testing, initially setting the admin -> user -> access for contentblocker module to Enabled for both anonymous and authenticated users.

So far, so good.

I connected with another browser (Opera) to play the part of the anonymous user. I noticed that "Content Blocker" was showing up in the navigation menu. I didn't think that looked right, so I went back to Access Control and set anonymous users to Disabled.

I hit refresh on the home page from the anonymous user's browser (Opera). The link disappeared. Good. I hit refresh a couple more times, then I got hit with this error which wouldn't go away until I reset Access Control for anonymous users to Enabled:

Fatal error: Call to undefined function drupal_get_path() in /var/www/drupal-5.1/sites/all/modules/contentblocker/contentblocker.module on line 346

After re-enabling anonymous users for the contentblocker module, it magically resolved the issue. Except that the Content Blocker menu item reappeared.

Looking at the chunk of code in question:

<?php
/**
* Load the include files used by this module.
*/
function contentblocker_load_modules() {
  static
$modules;
  if (
$modules == NULL) {
   
$modules = variable_get('contentblocker_modules', array());
    if (!empty(
$modules)) {
     
$path = drupal_get_path('module', 'contentblocker');
      foreach (
$modules as $module) {
        if (
module_exists($module)) {
          require_once
$path .'/modules/'. $module .'.inc';
        }
        else {
          unset(
$modules[$module]);
        }
      }
    }
  }
  return
$modules;
}
?>

Let me know if I can provide any more info.

#1

bg_dcp - July 16, 2007 - 23:33

I am experiencing the same problem, and can replicate the OP's experience, right down to having the Content Blocker menu item appear. This does not occur with Firefox, but does occur with Internet Explorer 6.0.29 (WinXP) and Konqueror (Debian Etch). I do not want this feature enabled for anonymous users.

#2

LoongFei - July 17, 2007 - 13:35

Excellent catch, there. I hadn't thought to approach this from the perspective of a more major browser.

So I re-enabled the module, and confirmed that this issue exists when not logged in via Opera (v9.21 if it matters).

I then logged in as the admin with Opera (after disabling the module via Firefox first to allow me to login under Opera, then re-enabling it) and logged out (became anonymous) from Firefox. Interestingly, the issue doesn't present itself. So I could well imagine that if the module developers were reading my OP and tried it with FF, they may have thought "cannot reproduce". ;-)

Given that I haven't seen any developer feedback yet, let's see if we can't somehow crack this one ourselves, or at least narrow it down.

I'll list all my modules in a sec, but the ones which seem (to me) to be ones to look at are ActiveMenu and DHTML Menus. Do you have either of those installed and active?

Otherwise, here's a brief listing of my modules dir:

acl adminblock backup bbcode bbcode_wysiwyg buddylist calendar captcha cck cck_ipaddr click commentmail comment_mover content_access contentblocker date devel dhtml_menu event fasttoggle form_store image jstools mycap og og_galleries phpfreechat privatemsg quick_child quote simplemenu subscriptions textimage tinymce troll uieforum update_status views websnapr wymeditor

NB: Not all of these are enabled, but I thought I'd mention them as a 'worst case' scenario. If you'd like me to list my active modules, I'll do so.

Both client (browsers) and server (Apache, Drupal) are installed on the same machine, which is running Ubuntu 7.04 (Feisty Fawn).

#3

LoongFei - July 17, 2007 - 13:53

So I went through the sit-ups of disabling/re-enabling ActiveMenu and DHTML Menus.

At first I thought I was onto something. When I would see the error in Opera and enable/disable a module via Firefox, the first refresh I would do in Opera after that would seem to clear the problem. Then I would click on a link to the home page, and the error would return. Hitting refresh one or more times after that wouldn't clear the error.

Until I enabled/disabled one/both of those two modules via Firefox, that is.

I soon realized this seemed to be some quirk of Opera and how it caches. At least that's my guess for now. I suppose I could try exercising IE (I've got Crossover Office installed) and see how that handles it.

The only 100% guaranteed workaround to this at present seems to be to disable the Content Blocker module, although I suspect that it's simply a matter of not playing nicely with a yet-to-be-identified module. Indeed, the mystery module in question could be (and probably is) the root cause, where throwing the error msg is simply how CB reacts to it.

#4

LoongFei - July 17, 2007 - 13:58

Yup, enabling CB and hitting it with IE 6.0.2800.1106 the error manifests itself in the same way as it does with Opera.

#5

Roberto Gerola - August 29, 2007 - 09:51

The problem is the init hook in the module.
It is safer to use menu hook instead.

Solution : delete the function contentblocker_init

The function contentblocker_menu should begin then as :

function contentblocker_menu($may_cache) {
contentblocker_load_modules();

$items = array();

Roberto

#6

nedjo - August 29, 2007 - 23:07
Status:active» needs review

I'd appreciate testing of the attached patch. Does it resolve the issue? Does it raise any new problems?

Follows Roberto Gerola's proposed approach. Also tries to address issue of menu items as per issue http://drupal.org/node/140327.

AttachmentSize
contentblocker-menu_0.patch 1.26 KB

#7

Roberto Gerola - August 30, 2007 - 12:56

Hi nedjo.
Made some tests yesterday.

Sadly it doesn't seem to be enough.
I have added contentblocker_load_modules() at the top of every
method that uses it.
It seems to work correctly now, but perhaps additional tests are necessary.

#8

nedjo - November 26, 2007 - 21:10
Component:User interface» Code
Category:support request» bug report
Priority:normal» critical
Assigned to:Anonymous» nedjo
Status:needs review» fixed

Fixed by adding conditional logic to hook_init() and covering the case with a call to load module-specific code in hook_menu(). Tested with and without page caching enabled, no further problems found.

#9

Anonymous - December 10, 2007 - 21:11
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.