You are here

function protected_node_update_7102 in Protected Node 7

Same name and namespace in other branches
  1. 1.0.x protected_node.install \protected_node_update_7102()

Manage "view protected content" permission deletion.

File

./protected_node.install, line 117
Install, update and uninstall functions for the protected_node module.

Code

function protected_node_update_7102() {

  // Get the rids with "view protected content".
  $rids = db_select('role_permission')
    ->fields('role_permission', array(
    'rid',
  ))
    ->condition('permission', 'view protected content')
    ->condition('module', 'protected_node')
    ->execute()
    ->fetchCol();

  // Get all permissions in the form of $permission => $module array.
  $permissions = user_permission_get_modules();
  if (isset($permissions['bypass password protection'])) {
    foreach ($rids as $rid) {

      // Give "bypass password protection" to roles with
      // "view protected content".
      user_role_grant_permissions($rid, array(
        'bypass password protection',
      ));

      // Remove "view protected content" from database.
      user_role_revoke_permissions($rid, array(
        'view protected content',
      ));
    }
  }
}