You are here

power_menu.install in Power Menu 7.2

Same filename and directory in other branches
  1. 6 power_menu.install
  2. 7 power_menu.install

just containing the stuff for install and uninstall

File

power_menu.install
View source
<?php

/**
 * @file
 *
 * just containing the stuff for install and uninstall
 */

/**
 * Implements hook_uninstall().
 */
function power_menu_uninstall() {
  variable_del('power_menu_handlers_settings');
  variable_del('power_menu_handlers_menus');
  variable_del('power_menu_handlers_enabled');
  variable_del('power_menu_handlers_breadcrumb');
  variable_del('power_menu_handlers_breadcrumb_title');
  variable_del('power_menu_path_bundles');
  variable_del('power_menu_path_number');
  variable_del('power_menu_node_bundles');
  variable_del('power_menu_taxonomy_vocabulary');
  variable_del('power_menu_taxonomy_terms');
}

/**
 * Implements hook_install().
 */
function power_menu_install() {

  // Nothing...
}

/**
 * Implements hook_schema().
 */
function power_menu_schema() {

  // Add a cache table for power menu
  $schema['cache_power_menu'] = drupal_get_schema_unprocessed('system', 'cache');
  $schema['power_menu_fields'] = array(
    'fields' => array(
      'id' => array(
        'description' => 'The primary identifier.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'menu_name' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The unique key for menu. This is used as a block delta so length is 32.',
      ),
      'mlid' => array(
        'description' => 'The menu link id',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'indexes' => array(
      'menu_name_mlid' => array(
        'menu_name',
        'mlid',
      ),
    ),
  );
  return $schema;
}

/**
 * Update version 6.x and 7.1 to 7.2 and migrate existing data to the new structure.
 */
function power_menu_update_7200() {

  // Add a new schema
  $schema = power_menu_schema();
  db_create_table('cache_power_menu', $schema['cache_power_menu']);
  db_create_table('power_menu_fields', $schema['power_menu_fields']);
  $settings = variable_get('power_menu_handlers_settings', array());

  // Menu selection
  $selected_menus = array();
  $menus = variable_get('power_menu_menu', array());
  foreach ($menus as $menu) {
    if ($menu !== 0) {
      $selected_menus[] = $menu;
    }
  }
  variable_set('power_menu_handlers_menus', $selected_menus);
  variable_del('power_menu_menu');

  // Breadcrumb settings
  variable_set('power_menu_handlers_breadcrumb_title', variable_get('power_menu_breadcrumb_title', FALSE));
  variable_del('power_menu_breadcrumb_title');

  // Set the selected navigation taxonomy
  $vid = variable_get('power_menu_taxonomy_navigation', '');
  $vocabulary = taxonomy_vocabulary_load($vid);
  if ($vocabulary) {
    $vocabulary = array(
      'vid' => $vocabulary->vid,
      'machine_name' => $vocabulary->machine_name,
    );
    variable_set('power_menu_taxonomy_vocabulary', $vocabulary);
  }
  variable_del('power_menu_taxonomy_navigation');

  // Update taxonomy related menu_links
  $result = db_select('power_menu', 'pm')
    ->fields('pm', array(
    'mlid',
    'tid',
  ))
    ->condition('pm.tid', 0, '<>')
    ->execute();
  $terms = array();
  foreach ($result as $item) {
    $terms[$item->tid] = $item->mlid;
  }
  variable_set('power_menu_taxonomy_terms', $terms);
  $settings['taxonomy']['enabled'] = count($terms) ? TRUE : FALSE;
  $settings['taxonomy']['weight'] = 1;

  // Update node related menu_links
  $result = db_select('power_menu', 'pm')
    ->fields('pm', array(
    'mlid',
    'nodetype',
    'tid',
  ))
    ->condition('pm.tid', 0, '=')
    ->execute();
  $bundles = array();
  foreach ($result as $item) {
    $ml = menu_link_load($item->mlid);
    $bundles['node|' . $item->nodetype] = array(
      'mlid' => $ml['mlid'],
      'link_path' => $ml['link_path'],
      'menu_name' => $ml['menu_name'],
      'router_path' => $ml['router_path'],
    );
  }
  variable_set('power_menu_node_bundles', $bundles);
  $settings['node']['enabled'] = count($bundles) ? TRUE : FALSE;
  $settings['node']['weight'] = 2;

  // Update path related content types
  $paths = array();
  foreach (variable_get('power_menu_path_content_types', array()) as $value) {
    if ($value !== 0) {
      $paths[] = 'node|' . $value;
    }
  }
  variable_set('power_menu_path_bundles', $paths);
  $settings['path']['enabled'] = count($paths) ? TRUE : FALSE;
  $settings['path']['weight'] = 3;
  variable_set('power_menu_handlers_settings', $settings);

  // Remove schema 'power_menu'
  db_drop_table('power_menu');

  // Migrate the properties to fields

  //db_drop_table('power_menu_properties');
}

/**
 * Rename all existing bundle names to proper machine names instead of menu keys with hyphens.
 */
function power_menu_update_7201() {

  // Update bundle names
  $menus = variable_get('power_menu_fields_menus', array());
  foreach ($menus as $key => $bundle_name_old) {
    $bundle_name_new = power_menu_create_machine_name($bundle_name_old);
    field_attach_rename_bundle('power_menu_fields', $bundle_name_old, $bundle_name_new);
  }

  // Update saved entities with new bundle names
  db_query("UPDATE power_menu_fields SET menu_name = REPLACE(menu_name,'-', '_')");
}

/**
 * Fix all Power Menu field bundle names for users updated to 7.x-2.0-beta2 before.
 */
function power_menu_update_7202() {

  // Update saved entities with new bundle names
  db_query("UPDATE power_menu_fields SET menu_name = REPLACE(menu_name,'-', '_')");
}

Functions

Namesort descending Description
power_menu_install Implements hook_install().
power_menu_schema Implements hook_schema().
power_menu_uninstall Implements hook_uninstall().
power_menu_update_7200 Update version 6.x and 7.1 to 7.2 and migrate existing data to the new structure.
power_menu_update_7201 Rename all existing bundle names to proper machine names instead of menu keys with hyphens.
power_menu_update_7202 Fix all Power Menu field bundle names for users updated to 7.x-2.0-beta2 before.