You are here

taxonomy_menu.install in Taxonomy menu 7

Install and uninstall all required databases. Also do incremental database updates.

File

taxonomy_menu.install
View source
<?php

/**
 * @file
 * Install and uninstall all required databases. Also do incremental database updates.
 */

/**
 * 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',
    'end_all',
    'flat',
    'max_depth',
    'term_item_description',
  );

  // Delete variables.
  $query = db_select('variable', 'v')
    ->fields('v', array(
    'name',
    'value',
  ))
    ->condition('name', '%' . db_like('taxonomy_menu') . '%', 'LIKE')
    ->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);
      }
    }
  }
}

/**
 * Implements hook_schema().
 */
function taxonomy_menu_schema() {
  $schema['taxonomy_menu'] = array(
    'description' => 'Links a taxonomy term to a menu item.',
    'fields' => array(
      'mlid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The taxonomy terms {menu_link}.mlid.',
      ),
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Tid that is linked to the mlid.',
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Vid for the tid.',
      ),
    ),
    'primary key' => array(
      'mlid',
      'tid',
    ),
    'indexes' => array(
      'vid' => array(
        'vid',
      ),
    ),
  );
  return $schema;
}

/**
 * Convert vocabulary ids into vocabulary machine names.
 */
function taxonomy_menu_update_7000() {
  $variable_prefixes = array(
    'vocab_menu',
    'vocab_parent',
    'voc_item',
    'display_num',
    'hide_empty_terms',
    'expanded',
    'rebuild',
    'path',
    'menu_end_all',
    'display_descendants',
    'voc_name',
    'sync',
  );
  $vocabularies = taxonomy_get_vocabularies();
  foreach ($vocabularies as $vocabulary) {
    foreach ($variable_prefixes as $prefix) {
      $old_name = 'taxonomy_menu_' . $prefix . '_' . $vocabulary->vid;
      $new_name = 'taxonomy_menu_' . $prefix . '_' . $vocabulary->machine_name;
      if (($value = variable_get($old_name)) !== NULL) {
        variable_set($new_name, $value);
        variable_del($old_name);
      }
    }
  }
}

Functions

Namesort descending Description
taxonomy_menu_schema Implements hook_schema().
taxonomy_menu_uninstall Implements hook_uninstall().
taxonomy_menu_update_7000 Convert vocabulary ids into vocabulary machine names.