You are here

taxonomy_menu.install in Taxonomy menu 7.2

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);

  // 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);
    }
  }
}

/**
 * Implements hook_install().
 */
function taxonomy_menu_install() {
}

/**
 * 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.',
      ),
      'language' => array(
        'description' => 'Language code, e.g. ’de’ or ’en-US’.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => LANGUAGE_NONE,
      ),
    ),
    'primary key' => array(
      'mlid',
      'tid',
      'language',
    ),
    '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);
      }
    }
  }
}

/**
 * Update database schema to handle languages.
 */
function taxonomy_menu_update_7200() {
  $schema = taxonomy_menu_schema();
  db_add_field('taxonomy_menu', 'language', $schema['taxonomy_menu']['fields']['language']);
  db_drop_primary_key('taxonomy_menu');
  db_add_primary_key('taxonomy_menu', $schema['taxonomy_menu']['primary key']);
}

Functions

Namesort descending Description
taxonomy_menu_install Implements hook_install().
taxonomy_menu_schema Implements hook_schema().
taxonomy_menu_uninstall Implements hook_uninstall().
taxonomy_menu_update_7000 Convert vocabulary ids into vocabulary machine names.
taxonomy_menu_update_7200 Update database schema to handle languages.