function rooms_booking_update_7006 in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
Update permission name for administer rooms_booking entities.
File
- modules/
rooms_booking/ rooms_booking.install, line 349 - Sets up the base table for our entity and a table to store information about the entity types.
Code
function rooms_booking_update_7006() {
$map = array(
'administer rooms_booking entities' => 'bypass rooms_booking entities access',
);
// Easy part: rename the permissions in {role_permission}.
foreach ($map as $old_name => $new_name) {
$roles = db_select('role_permission', 'r')
->fields('r', array(
'rid',
'permission',
))
->condition('permission', $old_name)
->execute()
->fetchAllKeyed();
foreach (array_keys($roles) as $rid) {
db_merge('role_permission')
->key(array(
'rid' => $rid,
'permission' => $new_name,
))
->fields(array(
'rid' => $rid,
'permission' => $new_name,
'module' => 'rooms_booking',
))
->execute();
db_delete('role_permission')
->condition('rid', $rid)
->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();
}
}
}