You are here

function cpn_update_7104 in Code per Node 7

Add the new CPN admin permission.

File

./cpn.install, line 364
Installation, schema and update hook implementations.

Code

function cpn_update_7104() {

  // Clear the caches prior to adding the new role.
  drupal_static_reset('user_access');
  drupal_static_reset('user_role_permissions');

  // The new permission to add.
  $new_permission = 'administer code per node';
  $roles = array();
  foreach (user_roles(TRUE, 'administer site configuration') as $rid => $role) {
    $roles[] = $role;
    db_merge('role_permission')
      ->key(array(
      'rid' => $rid,
      'permission' => $new_permission,
    ))
      ->fields(array(
      'module' => 'cpn',
    ))
      ->execute();
  }
  if (!empty($roles)) {
    drupal_set_message(format_plural(count($roles), 'Added the new user permission to the @roles role.', 'Added the new user permission to the @roles role(s).', array(
      '@roles' => implode(', ', $roles),
    )));

    // Update the permission caches again.
    drupal_static_reset('user_access');
    drupal_static_reset('user_role_permissions');
  }
}