You are here

function commerce_update_rename_permissions in Commerce Core 7

Utility function: rename a set of permissions.

3 calls to commerce_update_rename_permissions()
commerce_customer_update_7000 in modules/customer/commerce_customer.install
Update permission names for customer profile entity management.
commerce_order_update_7104 in modules/order/commerce_order.install
Update permission names for order entity management.
commerce_product_update_7101 in modules/product/commerce_product.install
Update permission names for product entity management.

File

./commerce.install, line 269

Code

function commerce_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();
    }
  }
}