Yow. After an update to a development site last night (replaced database), my users tried to log in and got only

Fatal error: Call to undefined function: arg() in  
/home/6048/domains/thevintageaviator.gomi.co.nz/html/sites/all/modules/modified/taxonomy_context-5-2/taxo
nomy_context.module  on line 266

(but not my sessions that were already logged in and non-caching).
I squealed "How can arg() not be available?!!!"

Seeing path.inc ...

* These functions are not loaded for cached pages, but modules that need
* to use them in hook_init() or hook exit() can make them available, by
* executing "drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);".

So I've added

/**
 * Implementation of hook_init().
 */
function taxonomy_context_init() {
	//
	//  THIS WAS CAUSING DEATH for anon users!
	//  Need to do this?
	drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);
	if(! function_exists('arg')){return;}
	
 	if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)) && empty($_GET['from'])) {
		// kludge: should probably have a setting here that allows you to prevent using taxcon breadcrumbs
		drupal_set_breadcrumb(taxonomy_context_get_breadcrumb(taxonomy_context_get_context()));
	}
}

Pretty nasty surprise. Never noticed before, probably because I only just enabled caching.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lee20’s picture

I think the use of the init hook in this case in unnecessary. Perhaps a better way to solve it would be to move the code that is executed in the init hook to the menu hook where there will be less issues with caching and it should resolve the issue.

dman’s picture

Agreed.
I didn't look much deeper at the time (dead site, client presentation upcoming at the time) but setting breadcrumbs is NOT a hook_init job!

mpaler’s picture

I'm getting this error on a fresh install as well for cached / anon user pages. Wondering on the status of this issue?

Agileware’s picture

Status: Active » Needs review
FileSize
890 bytes

This is a super critical issue.

Even if the 5 version isn't actually supported this needs to be done for the module
to be usable with caching, which being a drupal core functionality needs to be supported.

As lee20 says this doesn't really need to be done in hook_init but I don't have time to look into it
so here is a patch that implements dman's fix.

Agileware’s picture

Oh, and the patch is against 5.x-2.0

zirafi’s picture

Hi,

Could you let me know whether the above patch would help me to fix this issue.

I'm seeing the following error when I tried to login to the site after an upgrade from 5.x to 6.x.

Fatal error: Call to undefined function taxonomy_context_get_context() in /home/paradesi/public_html/includes/common.inc(1685) : eval()'d code on line 4

Immediate help is highly appreciated as my site was down already for two days.

thanks
~Paradesi

Agileware’s picture

@paradesi Apply the patch to find out :)

zirafi’s picture

Hi,

Thank you for quick answer.

I looked at the patch and it needs to be applied on module "taxonomy_context.module". But I don't see the module at all in the modules directory. So I'm wondering whether this patch is really applicable to my case.

~Paradesi

Agileware’s picture

@paradesi:

This patch is not for your problem.

Your problem is code somewhere on your site calling taxonomy_context_get_context() and the function doesn't exist.

To fix it you will either need to:
1. Install the taxonomy_context module (this is the easy solution if you don't know where the code is.
2. Find out where the code is that is calling that function and remove the call.
- It could be in a module somewhere or in your site settings somewhere that allows php code. For example views arguments or block content etc.

zirafi’s picture

I thought the same and I added the "taxonomy_context" module files into modules directory but I can not enable the module because I hit the same error again when I launched the site. Is there any other way to enable this module from command line ?

thanks

Agileware’s picture

If you know where the code is that is calling the function comment it out.

You can enable modules in your database if you have direct access to it.
All the modules and their enabled/disbled status is in the system table.

It isn't a good idea to use this as a substitute for installing a module though
as anything the module normally does during install in the taxonomy_context.install file
will not be done. So you would have to do that manually.

It would be good for your future reference to know what is calling this
function anyway or you could run into trouble down the line.
If it is a drupal module doing the calling it should have a dependency to
avoid this from happening.

zirafi’s picture

Thanks anyway. I hired someone to fix this issue.

kingandy’s picture

FileSize
1.07 KB

I don't think it's appropriate to force Drupal to bootstrap itself prematurely. As suggested in the hook_init docs, this should be moved to the the !$may_cache clause of the hook_menu() implementation (which gets called once for each page, and is called after Drupal finishes calling itself into existence).

Find attached a patch to achieve this. Tested on a production site.