While attempting to uninstall the mongodb_watchdog module I received the following error:

[Thu Jul 25 02:14:46 2013] [error] [client 174.84.232.114] PHP Fatal error: Call to undefined function mongodb_collection() in /var/www/vhosts/example.com/sites/all/modules/mongodb/mongodb_watchdog/mongodb_watchdog.install on line 30, referer: http://example.com/admin/modules/uninstall/confirm

Comments

sprice’s picture

Status: Active » Needs review

It's an easy fix. Just drop

include_once dirname(__FILE__) . '/../mongodb.module';

into the mongodb_watchdog.install file.

fgm’s picture

Issue summary: View changes
Status: Needs review » Postponed (maintainer needs more info)

Cannot reproduce the problem : when uninstalling, mongodb.module is always loaded when hook_uninstall() is triggered.

Can you detail your configuration and reproduce the problem on a blank install with just the mongodb and mongodb_watchdog modules, step by step, like this:

  • php 5.4.10, drush latest 7.0-dev, drupal 7.34, latest mongodb 7.x-1.x
  • drush si -y
  • drush en -y mongodb_watchdog
  • drush dis -y mongodb_watchdog
  • drush pm-uninstall -y mongodb_watchdog
  • drush dis -y mongodb
  • drush pm-uninstall -y mongodb

I also checked with the web UI instead of Drush. No such problem.

Anonymous’s picture

I didn't try to replicate this on a clean system with only the mongodb and mongodb_watchdog modules, but I *can* confirm that I did have this problem, & that the solution in #1 worked for me.

ryumkin’s picture

Same alert but on mongodb install. I've installed rc2, then receive message about deprecated functions, uninstall and delete it, downlad dev version, and tryied to enable basic mongodb module.
BTW mongodb() and mongodb_collection() functions where from? From Drupal module or PHP module?
Thank you.

fgm’s picture

@rhclayto @ryumkin To help you I need a reproducible scenario starting from a fresh install (with the dev version), and just the mongodb and mongodb_watchdog modules : I have not been able to obtain this problem on my configurations.

@ryumkin : they are in mongodb.module.

ryumkin’s picture

I don't think that the result of fresh install would be different. I did a small research and it seems like .module file don't load if the requirements not met. So this is a cycle hook_requirements required .module to execute, and .module needs hook_requirements to execute. I put watchdog("include", json_encode(get_included_files())); in your hook_requirements and there was no mongodb.module file. Also I found the following:

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...

Various pages mention the automated loading of the .module file if hook_requirements is satisfied. The load occurs only for hook_install but not for hook_uninstall or hook_update_*.

https://www.drupal.org/node/1555220

hook_requirements can, in install.php, be run before the system table is even created, and so module_load_include and a libraries function can not be called safely.

https://www.drupal.org/node/2364737

In hook_requirements(), kissmetrics_check_directory() is used, which is defined in the .module file. It is not certain that the module file is already loaded when hook_requirements() is invoked: it will be surely included after the requirements are satisfied. Therefore, we have to load is explicitly.

Of course the best would be to trace drupal core code, hope I would find some time to proove it, meanwhile I would just include .module in .install as #1 recommends.

ryumkin’s picture

BTW

include_once dirname(__FILE__) . '/../mongodb.module';

is not a good way to include the file, it depens on folders hierarchy, the following is better:

module_load_include('module', 'mongodb', 'mongodb');

fgm’s picture

@ryumkin : module_load_include() is indeed needed when including files /not/ part of your package because you cannot know where the files are without asking core, but direct inclusions with dirname(__FILE__) or __DIR__ are the best way /within/ a given package, since as the package author you are in charge of the relative file layout below the package root, and this saves some function calls, and dependency on having drupal_get_path() be able to find the package, which is not a given in some circumstances.

To go further, I think the best way to proceed is to provide a failing Simpletest causing the error. Then we'll know the issue is fixed when the test passes.

fgm’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)
Related issues: +#2567211: WSOD on enabling mongodb and uninstalling mongodb_watchdog

Actually, I eventually managed to reproduce it : the key was to try to uninstall mongodb_watchdog after having disabled mongodb. This is now addressed as part of the patches for #2567211: WSOD on enabling mongodb and uninstalling mongodb_watchdog, so marking this one closed.

nehapandya55’s picture

Hi,

I faced same problem but #1 did not work for me. But when i drop include_once dirname(__FILE__) . '/../mongodb.module'; from module mongodb_watchdog.module file and added module_load_include('module', 'mongodb', 'mongodb'); to mongodb_watchdog.install file under mongodb_watchdog_uninstall() function worked for me and successfully uninstalled mongodb module.