You are here

function rooms_update_rename_permissions in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Utility function: rename a set of permissions.

2 calls to rooms_update_rename_permissions()
rooms_availability_update_7001 in modules/rooms_availability/rooms_availability.install
Renames permissions.
rooms_pricing_update_7001 in modules/rooms_pricing/rooms_pricing.install
Renames permissions.

File

./rooms.install, line 80
Install, update and uninstall functions for the rooms module.

Code

function rooms_update_rename_permissions($map) {

  // Easy part: rename the permissions in {role_permission}.
  foreach ($map as $old_name => $new_name) {
    db_update('role_permission')
      ->fields(array(
      'permission' => $new_name,
    ))
      ->condition('permission', $old_name)
      ->execute();
  }

  // Trickier: rename the permission for the in-database Views.
  foreach (views_get_all_views() as $view) {
    if ($view->type == t('Default')) {
      continue;
    }
    $save_view = FALSE;
    foreach ($view->display as $display_name => $display) {
      if (!empty($display->display_options['access']['type']) && $display->display_options['access']['type'] == 'perm') {
        $permission_name = $display->display_options['access']['perm'];
        if (isset($map[$permission_name])) {
          $display->display_options['access']['perm'] = $map[$permission_name];
          $save_view = TRUE;
        }
      }
    }
    if ($save_view) {
      $view
        ->save();
    }
  }
}