You are here

function adminrole_update_permissions in Admin role 7

Same name and namespace in other branches
  1. 5 adminrole.module \adminrole_update_permissions()
  2. 6 adminrole.module \adminrole_update_permissions()

Update the admin role with all current available permissions.

5 calls to adminrole_update_permissions()
adminrole_enable in ./adminrole.install
Implements hook_enable().
adminrole_field_delete_field in ./adminrole.module
adminrole_field_update_field in ./adminrole.module
adminrole_node_type_update in ./adminrole.module
Respond to fields/entities being created, updated, deleted - NOTE - this is the wrong code fore this!!
drush_adminrole_update in ./adminrole.drush.inc
Drush callback; update the admin role with all current available permissions.
1 string reference to 'adminrole_update_permissions'
adminrole_form_alter in ./adminrole.module
Implements hook_form_alter().

File

./adminrole.module, line 66
This module simply gives a designated role all permissions every time the modules page is submitted.

Code

function adminrole_update_permissions() {
  static $messaged;
  if ($rid = variable_get('user_admin_role', 0)) {
    foreach (module_implements('permission') as $module) {
      foreach (module_invoke($module, 'permission') as $key => $perm) {
        $perms[$key] = $module;
      }
    }

    /*if ($excluded = variable_get('adminrole_exclude_permissions', array())) {
        $permissions = array_diff($permissions, $excluded);
      } */

    /** change from doing a DELETE ALL and INSERT to a MERGE which does insert/update as required
     *     - no obvious performance hit doing this but there may be cases where we don't want to remove
     *     records that don't have a module assoicated with them (e.g. shared tables)
     */
    if ($perms) {
      foreach ($perms as $perm => $module) {
        $query = db_merge('role_permission');
        $query
          ->key(array(
          'rid' => $rid,
          'permission' => $perm,
        ));
        $query
          ->fields(array(
          'rid' => $rid,
          'permission' => $perm,
          'module' => $module,
        ));
        $query
          ->execute();
      }
      $role = db_query("SELECT name FROM {role} WHERE rid = :rid", array(
        ":rid" => $rid,
      ))
        ->fetchField();
      if (!$messaged) {
        drupal_set_message(t("The <em>@role</em> role has been reset for all permissions.", array(
          "@role" => $role,
        )));
        $messaged = TRUE;
      }
    }
  }
}