Hello,

I am the maintainer of Taxonomy menu block, a module that does the same as this one but has a completely different approach.

I have noticed that when uninstalling Taxonomy menu, this code gets run in hook_uninstall:

// Delete variables
  $query = db_select('variable', 'v')->fields('v')->execute();
  $variables = $query->fetchAll();
  foreach ($variables as $variable) {
    if (strpos($variable->name, 'taxonomy_menu') !== FALSE) {
      variable_del($variable->name);
    }
  }

This uninstalls all variables that are named taxonomy_menu%, meaning also the variables for my module. There should be done a more specific deletion of variables.

Comments

kbrinner’s picture

Issue summary: View changes
StatusFileSize
new1.42 KB

I have created a patch for this so Taxonomy Menu is more specific when checking variables for deletion upon uninstalling the module. This prevents variables associated with the Taxonomy Menu Block from being deleted along with the Taxonomy Menu variables.

With the applied patch, the uninstall function is now:

/**
 * Implements hook_uninstall().
 */
function taxonomy_menu_uninstall() {

  //remove menu items
  db_delete('menu_links')->condition('module', 'taxonomy_menu', '=')->execute();

  //rebuild the menus
  variable_set('menu_rebuild_needed', TRUE);

  // Gets array of more specific variables set by Taxonomy Menu module.
  // This prevents known issue https://www.drupal.org/node/1966684
  // where uninstalling Taxonomy Menu will delete variables related
  // to the Taxonomy Menu Block module.
  $variable_suffixes = array(
    'vocab_menu',
    'vocab_parent',
    'voc_item',
    'display_num',
    'hide_empty_terms',
    'expanded',
    'rebuild',
    'path',
    'menu_end_all',
    'display_descendants',
    'voc_name',
    'sync',
  );

  // Delete variables.
  $query = db_select('variable', 'v')->fields('v')->execute();
  $variables = $query->fetchAll();
  foreach ($variables as $variable) {
    // Add check to make sure we only delete variables for Taxonomy Menu,
    // not variables for Taxonomy Menu Block.
    foreach ($variable_suffixes as $suffix) {
      $taxonomy_menu_variable_name = 'taxonomy_menu_' . $suffix;
      if (strpos($variable->name, $taxonomy_menu_variable_name) !== FALSE) {
        variable_del($variable->name);
      }
    }
  }
}
jenlampton’s picture

Status: Active » Reviewed & tested by the community

Looks great, nice catch, nice clean fix. Thank you @kbrinner

jenlampton’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.68 KB

Back to NR, since it looks like we missed a few variables. New patch attached. (I also added a db_like condition to the query, hoping to save us some time in that loop during uninstall)

Status: Needs review » Needs work

The last submitted patch, 3: taxonomy_menu-uninstall_too_general-1966684-3.patch, failed testing.

jenlampton’s picture

Status: Needs work » Needs review

funny, this shouldn't affect tests. trying again.

andrey.troeglazov’s picture

Assigned: Unassigned » andrey.troeglazov
andrey.troeglazov’s picture

Relaunched tests.

andrey.troeglazov’s picture

andrey.troeglazov’s picture

Assigned: andrey.troeglazov » Unassigned
Status: Needs review » Reviewed & tested by the community

Now patch looks ok and tests passed.

andrey.troeglazov’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: +Taxonomy menu release 7-1.6

Status: Fixed » Closed (fixed)

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