You are here

function submenutree_update_7201 in Submenu Tree 7.2

Update submenu view mode settings.

File

./submenutree.install, line 191
Install, update and uninstall functions for the Submenu Tree module.

Code

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