You are here

function _role_watchdog_add_role in Role Watchdog 7

Same name and namespace in other branches
  1. 5 role_watchdog.module \_role_watchdog_add_role()
  2. 6.2 role_watchdog.module \_role_watchdog_add_role()
  3. 6 role_watchdog.module \_role_watchdog_add_role()
  4. 7.2 role_watchdog.module \_role_watchdog_add_role()

Internal function

Handles addition of roles.

1 call to _role_watchdog_add_role()
_role_watchdog_process_role_changes in ./role_watchdog.module

File

./role_watchdog.module, line 234
Logs changes to user roles.

Code

function _role_watchdog_add_role($rid, $account) {
  global $user;
  $roles = user_roles();
  $record = array(
    'aid' => $account->uid,
    'rid' => $rid,
    'action' => ROLE_WATCHDOG_ROLE_ADD,
    'uid' => $user->uid,
    'stamp' => REQUEST_TIME,
  );
  if (drupal_write_record('role_watchdog', $record)) {
    $vars = array(
      'body' => 'Role !role!role_modifier added to !account by !user',
      '!role' => check_plain($roles[$rid]),
      '!user' => check_plain($user->name),
      '!user_id' => $user->uid,
      '!account' => check_plain($account->name),
      '!account_id' => $account->uid,
    );
    watchdog('role_watchdog', $vars['body'], $vars, WATCHDOG_NOTICE, l(t('view'), 'user/' . $account->uid . '/track/role_history'));
    _role_watchdog_notification($rid, $vars);
    return $record;
  }
  else {
    watchdog('role_watchdog', 'Unable to save record in _role_watchdog_add_role()', array(), WATCHDOG_ERROR, l(t('view'), 'user/' . $account->uid . '/track/role_history'));
    return ROLE_WATCHDOG_ROLE_NOCHANGE;
  }
}