You are here

submenutree.install in Submenu Tree 7.2

Same filename and directory in other branches
  1. 5 submenutree.install
  2. 6 submenutree.install
  3. 7 submenutree.install

Install, update and uninstall functions for the Submenu Tree module.

File

submenutree.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Submenu Tree module.
 */

/**
 * Implements hook_schema().
 */
function submenutree_schema() {
  $schema['node_submenutree'] = array(
    'description' => t('The base table for submenutree.'),
    'fields' => array(
      'nid' => array(
        'description' => 'The primary identifier for a node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'submenutree_enable' => array(
        'description' => 'The status of sub content associated with this node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'submenutree_title' => array(
        'description' => 'The title for the sub content associated with this node.',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
      ),
      'submenutree_display' => array(
        'description' => 'The method of displaying sub content associated with this node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'submenutree_view_mode' => array(
        'description' => 'The view mode of sub content associated with this node.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => 'full',
      ),
      'submenutree_links' => array(
        'description' => 'Wheter or not to display links for sub content associated with this node.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'siblingmenutree_enable' => array(
        'description' => 'The status of sibling content associated with this node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'siblingmenutree_title' => array(
        'description' => 'The title for the sibling content associated with this node.',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
      ),
      'siblingmenutree_display' => array(
        'description' => 'The method of displaying sibling content associated with this node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'siblingmenutree_view_mode' => array(
        'description' => 'The view mode of sibling content associated with this node.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => 'full',
      ),
      'siblingmenutree_links' => array(
        'description' => 'Wheter or not to display links for sibling content associated with this node.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  return $schema;
}

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

  // Clear the configuration variables
  variable_del('submenutree_block_title');
  variable_del('submenutree_block_title_content_menu_parent_level');
  variable_del('submenutree_extended_menu_name');
  variable_del('submenutree_extended_menu_level');

  // Clear the node specific variables
  $types = node_type_get_names();
  foreach ($types as $type => $name) {
    variable_del("submenutree_node_type_{$type}");
    variable_del("submenutree_enable_{$type}");
    variable_del("submenutree_title_{$type}");
    variable_del("submenutree_display_{$type}");
    variable_del("submenutree_weight_{$type}");
    variable_del("siblingmenutree_enable_{$type}");
    variable_del("siblingmenutree_title_{$type}");
    variable_del("siblingmenutree_display_{$type}");
    variable_del("siblingmenutree_weight_{$type}");
    variable_del("siblingmenutree_view_mode_{$type}");
    variable_del("siblingmenutree_links_{$type}");
  }
}

/**
 * Make columns submenutree_weight and siblingmenutree_weight signed integers.
 * See http://drupal.org/node/455690
 */
function submenutree_update_6001() {
  $fields = array(
    'submenutree_weight' => array(
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0,
      'disp-width' => '10',
    ),
    'siblingmenutree_weight' => array(
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0,
      'disp-width' => '10',
    ),
  );
  $ret = array();
  foreach ($fields as $field => $spec) {
    db_change_field($ret, 'node_submenutree', $field, $field, $spec);
  }
  return $ret;
}

/**
 * Update roles with Submenu Tree 7.x-1.x permissions.
 */
function submenutree_update_7200() {

  // Find every role with sub or sibling content permissions
  $sub_content_roles = user_roles(FALSE, 'administer submenu trees');
  $sibling_content_roles = user_roles(FALSE, 'administer siblingmenu trees');

  // Define which permissions should be added and removed from roles with the old "administer submenu trees" permission
  $new_sub_content_permissions = array(
    'administer submenu trees' => FALSE,
    'administer sub content' => TRUE,
    'administer sub content title' => TRUE,
    'administer sub content display type' => TRUE,
    'administer sub content weight' => TRUE,
  );

  // Define which permissions should be added and removed from roles with the old "administer siblingmenu trees" permission
  $new_sibling_content_permissions = array(
    'administer siblingmenu trees' => FALSE,
    'administer sibling content' => TRUE,
    'administer sibling content title' => TRUE,
    'administer sibling content display type' => TRUE,
    'administer sibling content weight' => TRUE,
  );

  // Update roles with the old sub content permission
  foreach ($sub_content_roles as $role_id => $role_name) {
    user_role_change_permissions($role_id, $new_sub_content_permissions);
  }

  // Update roles with the old sibling content permission
  foreach ($sibling_content_roles as $role_id => $role_name) {
    user_role_change_permissions($role_id, $new_sibling_content_permissions);
  }
  return t('Successfully migrated all user roles with old Submenu Tree permissions.');
}

/**
 * Update submenu view mode settings.
 */
function submenutree_update_7201() {

  // Find every role with sub or sibling content permissions
  $sub_content_roles = user_roles(FALSE, 'administer sub content display type');
  $sibling_content_roles = user_roles(FALSE, 'administer sibling content display type');

  // Define which permissions should be added and removed from roles.
  $new_sub_content_permissions = array(
    'administer sub content view mode' => TRUE,
  );

  // Define which permissions should be added and removed from roles.
  $new_sibling_content_permissions = array(
    'administer sibling content view mode' => TRUE,
  );

  // Update roles with the old sub content permission
  foreach ($sub_content_roles as $role_id => $role_name) {
    user_role_change_permissions($role_id, $new_sub_content_permissions);
  }

  // Update roles with the old sibling content permission
  foreach ($sibling_content_roles as $role_id => $role_name) {
    user_role_change_permissions($role_id, $new_sibling_content_permissions);
  }

  // Add the new columns.
  db_add_field('node_submenutree', 'submenutree_view_mode', array(
    'description' => 'The view mode of sub content associated with this node.',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => 'full',
  ));
  db_add_field('node_submenutree', 'submenutree_links', array(
    'description' => 'Wheter or not to display links for sub content associated with this node.',
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_field('node_submenutree', 'siblingmenutree_view_mode', array(
    'description' => 'The view mode of sibling content associated with this node.',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => 'full',
  ));
  db_add_field('node_submenutree', 'siblingmenutree_links', array(
    'description' => 'Wheter or not to display links for sibling content associated with this node.',
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));

  // Update existing configuration.
  db_update('node_submenutree')
    ->fields(array(
    'submenutree_links' => 1,
  ))
    ->condition('submenutree_display', array(
    3,
    5,
  ))
    ->execute();
  db_update('node_submenutree')
    ->fields(array(
    'siblingmenutree_links' => 1,
  ))
    ->condition('siblingmenutree_display', array(
    3,
    5,
  ))
    ->execute();
  db_update('node_submenutree')
    ->fields(array(
    'submenutree_view_mode' => 'teaser',
  ))
    ->condition('submenutree_display', array(
    2,
    3,
  ))
    ->execute();
  db_update('node_submenutree')
    ->fields(array(
    'siblingmenutree_view_mode' => 'teaser',
  ))
    ->condition('siblingmenutree_display', array(
    2,
    3,
  ))
    ->execute();
  db_drop_field('node_submenutree', 'submenutree_weight');
  db_drop_field('node_submenutree', 'siblingmenutree_weight');

  // Update the variables.
  $types = node_type_get_names();
  foreach (array_keys($types) as $type) {
    $display_type = variable_get("submenutree_display_{$type}", FALSE);
    switch ($display_type) {
      case 2:
        variable_set("submenutree_display_{$type}", SUBMENUTREE_DISPLAY_VIEW_MODE);
        variable_set("submenutree_view_mode_{$type}", 'teaser');
        variable_set("submenutree_links_{$type}", FALSE);
        break;
      case 3:
        variable_set("submenutree_display_{$type}", SUBMENUTREE_DISPLAY_VIEW_MODE);
        variable_set("submenutree_view_mode_{$type}", 'teaser');
        variable_set("submenutree_links_{$type}", TRUE);
        break;
      case 4:
        variable_set("submenutree_display_{$type}", SUBMENUTREE_DISPLAY_VIEW_MODE);
        variable_set("submenutree_view_mode_{$type}", 'full');
        variable_set("submenutree_links_{$type}", FALSE);
        break;
      case 5:
        variable_set("submenutree_display_{$type}", SUBMENUTREE_DISPLAY_VIEW_MODE);
        variable_set("submenutree_view_mode_{$type}", 'full');
        variable_set("submenutree_links_{$type}", TRUE);
        break;
    }
    variable_del("submenutree_weight_{$type}");
    variable_del("siblingmenutree_enable_{$type}");
    variable_del("siblingmenutree_title_{$type}");
    variable_del("siblingmenutree_display_{$type}");
    variable_del("siblingmenutree_weight_{$type}");
    variable_del("siblingmenutree_view_mode_{$type}");
    variable_del("siblingmenutree_links_{$type}");
  }
}

Functions

Namesort descending Description
submenutree_schema Implements hook_schema().
submenutree_uninstall Implements hook_uninstall().
submenutree_update_6001 Make columns submenutree_weight and siblingmenutree_weight signed integers. See http://drupal.org/node/455690
submenutree_update_7200 Update roles with Submenu Tree 7.x-1.x permissions.
submenutree_update_7201 Update submenu view mode settings.