示例#1
0
 function revokeRole($name)
 {
     if (Event::handle('StartRevokeRole', array($this, $name))) {
         $role = Profile_role::pkeyGet(array('profile_id' => $this->id, 'role' => $name));
         if (empty($role)) {
             // TRANS: Exception thrown when trying to revoke an existing role for a user that does not exist.
             // TRANS: %1$s is the role name, %2$s is the user ID (number).
             throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; does not exist.'), $name, $this->id));
         }
         $result = $role->delete();
         if (!$result) {
             common_log_db_error($role, 'DELETE', __FILE__);
             // TRANS: Exception thrown when trying to revoke a role for a user with a failing database query.
             // TRANS: %1$s is the role name, %2$s is the user ID (number).
             throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; database error.'), $name, $this->id));
         }
         if ($name == 'owner') {
             User::blow('user:site_owner');
         }
         Event::handle('EndRevokeRole', array($this, $name));
         return true;
     }
 }
 function revokeRole($name)
 {
     $role = Profile_role::pkeyGet(array('profile_id' => $this->id, 'role' => $name));
     if (empty($role)) {
         throw new Exception('Cannot revoke role "' . $name . '" for user #' . $this->id . '; does not exist.');
     }
     $result = $role->delete();
     if (!$result) {
         common_log_db_error($role, 'DELETE', __FILE__);
         throw new Exception('Cannot revoke role "' . $name . '" for user #' . $this->id . '; database error.');
     }
     return true;
 }