You are here

function cas_drush_user_add_role in CAS 6.3

Same name and namespace in other branches
  1. 7 cas.drush.inc \cas_drush_user_add_role()

Add a role to the specified CAS user accounts.

1 string reference to 'cas_drush_user_add_role'
cas_drush_command in ./cas.drush.inc
Implements hook_drush_command().

File

./cas.drush.inc, line 79
Drush commands for CAS.

Code

function cas_drush_user_add_role($role, $users = '') {
  $uids = cas_drush_user_get_users_from_arguments($users);
  if (drush_drupal_major_version() >= 7) {
    $rid_query = db_query("SELECT rid FROM {role} WHERE name = :role", array(
      ':role' => $role,
    ));
  }
  else {
    $rid_query = db_query("SELECT rid FROM {role} WHERE name = '%s'", $role);
  }
  if (!empty($uids)) {
    if ($rid = drush_db_result($rid_query)) {
      drush_op('user_multiple_role_edit', $uids, 'add_role', $rid);
      foreach ($uids as $uid) {
        drush_log(dt("Added the !role role to uid !uid", array(
          '!role' => $role,
          '!uid' => $uid,
        )), 'success');
      }
    }
    else {
      return drush_set_error(dt("There is no role named: !role", array(
        '!role' => $role,
      )));
    }
  }
  else {
    return drush_set_error("Could not find any valid uids!");
  }
}