Fatal error: Call to undefined function shortcut_sets() in /path/to/drupal/modules/shortcut/shortcut.install on line 36

How to replicate:

  1. Fresh 7.2 install
  2. Disable shortcut module
  3. Uninstall shortcut module

If using overlay the error flashes briefly before redirecting to /admin/modules, turn overlay off to see the full error message.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jamestombs’s picture

I am getting the same.

Adding the following to the shortcut.install file fixes the problem:


if (!function_exists('shortcut_sets')) {
  function shortcut_sets() {
    return db_select('shortcut_set', 'ss')
    ->fields('ss')
    ->execute()
    ->fetchAllAssoc('set_name');
  }
}
alexweber’s picture

It'll work but the proper way to handle this would be to make sure shortcut.module is included at that point and, if not, include it.

Alan D.’s picture

Related to #1029606: Regression: Not loading the .module file causes a fatal error when uninstalling some modules (as does loading it). I'm not sure if we should mark this as a duplicate or not.

After a visual review of some of the uninstall files, this seems redundant in the forum module:

forum.install

/**
 * Implements hook_uninstall().
 */
function forum_uninstall() {
  // Load the dependent Taxonomy module, in case it has been disabled.
  drupal_load('module', 'taxonomy');

  variable_del('forum_containers');
  ....
}

And this should cause an error in the simpletest module, unless class autoloading saves the day, which was the reason that the module_load_include() was removed in the first place.

simpletest.install

/**
 * Implements hook_uninstall().
 */
function simpletest_uninstall() {
  simpletest_clean_environment();

  // Remove settings variables.
  ....
}
Devin Carlson’s picture

Just reporting that I've also run into this issue and it is easily duplicated as outlined in the original post.

Andrew Schulman’s picture

Subscribing

Alan D.’s picture

A quick one off hack for subscribers, simply add the following line to the top of the uninstall function of the problematic module:

module_load_include('module', 'shortcut');
Garrett Albright’s picture

Status: Active » Needs review
FileSize
0 bytes

Status: Needs review » Needs work

The last submitted patch, 1169894-uninstall-shortcut.patch, failed testing.

Garrett Albright’s picture

Status: Needs work » Needs review
FileSize
832 bytes

D'oh.

Status: Needs review » Needs work

The last submitted patch, 1169894-uninstall-shortcut.patch, failed testing.

alexweber’s picture

I'm unclear as to what the "best" solution here is: should we manually load the .module file as proposed in #6 or make a db call to get the info as proposed by #9?

Despite accessing the db being the more practical route its less future-proof as the "correct" way would be to use the API whenever possible.

alexweber’s picture

Status: Needs work » Needs review
FileSize
490 bytes

This should work :)

Status: Needs review » Needs work

The last submitted patch, 1169894-uninstall-shortcut.patch, failed testing.

Garrett Albright’s picture

I presume there's some reason .module files aren't loaded when their uninstall hooks run, so I opted not to circumvent that. I'll let smarter people determine what the best approach is.

Also, will someone go kick the test robot, please?

Alan D.’s picture

There was no real reason for the removal of the include other than to tidy things up after hook_menu() was removed. Sadly a simple API change that caused this bug. There should be zero danger of including the module file.

By including logic in the install file results in duplication of code, which means this then needs to be maintained twice, so I would favor the include approach.

alexweber’s picture

Agreed!

On a lighter note, why did the test bot spit at my patch?

Garrett Albright’s picture

Status: Needs work » Reviewed & tested by the community

Test Bot had issues yesterday. But it's passed since then (looks like someone kicked it).

I concur with Alan D. that code duplication is not ideal. If including the .module file won't cause problems, then that is the preferable approach.

webchick’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7
Garrett Albright’s picture

Issue tags: -Needs backport to D7

The patch was already made against D7 core, and also applies cleanly to HEAD of 8.x (I just tested). So removing the tag.

tstoeckler’s picture

Issue tags: +Needs backport to D7

The tag is a reminder for committers to not forget to commit this patch to D7 and for reviewers to track the correct issues. Re-adding tag.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Postponed

Since Shortcut module wasn't the only one broken by this change (not even in core, let alone contrib!) I think we should postpone this on the discussion in #1029606: Regression: Not loading the .module file causes a fatal error when uninstalling some modules (as does loading it), so we can figure out how to solve this consistently across all modules. We don't want to keep it postponed for too long, though, since this ideally should be fixed before 7.3 is released.

In terms of this issue, either patch works, but I think I prefer Garrett Albright's approach a bit. The automatic loading of .module files was removed because it was breaking some modules' uninstallation (ones that defined classes that depended on other modules). That's not an issue for shortcut.module at the moment, but if we're saying it's bad practice to load a disabled module's .module file we probably should follow that here too. We already have similar conventions for hook_update_N(), so it seems like it would make sense to apply the same convention here. Let's wait and see what happens with the discussion in the other issue.

This probably also needs tests, although the goal of the other issue is to have a test that handles this for all core modules at once, so it might be covered by that one instead.

geerlingguy’s picture

Subscribe. Annoying to have to do this dance every time I want to uninstall some of the core modules.

David_Rothstein’s picture

Status: Postponed » Needs review

Based on discussion in #1029606: Regression: Not loading the .module file causes a fatal error when uninstalling some modules (as does loading it) it sounds like we should go with the approach of including the .module file, so let's reopen this.

But I'm pretty sure to be consistent with general usage we should use drupal_load() rather than module_load_include() here?

aspilicious’s picture

Status: Needs review » Closed (duplicate)

This is now a duplicate, last patch in the other issue does this alrdeady.

function shortcut_uninstall() {
+  drupal_load('module', 'shortcut');
   // Delete the menu links associated with each shortcut set.