### Eclipse Workspace Patch 1.0
#P Drupal HEAD (Core)
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.717
diff -u -r1.717 user.module
--- modules/user/user.module	23 Nov 2006 11:06:53 -0000	1.717
+++ modules/user/user.module	24 Nov 2006 10:17:05 -0000
@@ -2184,32 +2184,63 @@
  * Callback function for admin mass unblocking users.
  */
 function user_user_operations_unblock($accounts) {
-  db_query('UPDATE {users} SET status = 1 WHERE uid IN(%s)', implode(',', $accounts));
+  foreach ($accounts as $uid) {
+    $account = user_load(array('uid' => $uid));
+    // Skip unblocking user if they are already unblocked.
+    if ($account->status == 0) {
+      user_save($account, array('status' => 1));
+      // We don't need to clear this user's cache_menu here as it get's cleared
+      // by user_admin_account_submit().
+    }
+  }
 }
 
 /**
  * Callback function for admin mass blocking users.
  */
 function user_user_operations_block($accounts) {
-  db_query('UPDATE {users} SET status = 0 WHERE uid IN(%s)', implode(',', $accounts));
+  foreach ($accounts as $uid) {
+    $account = user_load(array('uid' => $uid));
+    // Skip blocking user if they are already blocked.
+    if ($account->status == 1) {
+      user_save($account, array('status' => 0));
+      // We don't need to clear this user's cache_menu here as it get's cleared
+      // by user_admin_account_submit().
+    }
+  }
 }
 
 /**
  * Callback function for admin mass adding/deleting a user role.
  */
 function user_multiple_role_edit($accounts, $operation, $rid) {
+  // The role name is not necessary as user_save() will reload the user
+  // object, but some modules' hook_user() may look at this first.
+  $role_name = db_result(db_query('SELECT name FROM {role} WHERE rid = %d', $rid));
+
   switch ($operation) {
     case 'add_role':
       foreach ($accounts as $uid) {
+        $account = user_load(array('uid' => $uid));
         // Skip adding the role to the user if they already have it.
-        if (!db_result(db_query('SELECT uid FROM {users_roles} WHERE uid = %d AND rid = %d', $uid, $rid))) {
-          db_query('INSERT INTO {users_roles} VALUES (%d, %d)', $uid, $rid);
+        if (!isset($account->roles[$rid])) {
+          $roles = $account->roles + array($rid => $role_name);
+          user_save($account, array('roles' => $roles));
+          // We don't need to clear this user's cache_menu here as it get's cleared
+          // by user_admin_account_submit().
         }
       }
       break;
     case 'remove_role':
       foreach ($accounts as $uid) {
-        db_query('DELETE FROM {users_roles} WHERE rid = %d AND uid IN(%s)', $rid, implode(',', $accounts));
+        $account = user_load(array('uid' => $uid));
+        // Skip removing the role from the user if they already don't have it.
+        if (isset($account->roles[$rid])) {
+          $roles = array_diff($account->roles, array($rid => $role_name));
+          user_save($account, array('roles' => $roles));
+          // We don't need to clear this user's cache_menu here as it get's cleared
+          // by user_admin_account_submit().
+        }
       }
       break;
   }
