### 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.721
diff -u -r1.721 user.module
--- modules/user/user.module	26 Nov 2006 02:20:01 -0000	1.721
+++ modules/user/user.module	29 Nov 2006 09:39:38 -0000
@@ -2184,32 +2184,55 @@
  * 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' => (int)$uid));
+    // Skip unblocking user if they are already unblocked.
+    if ($account !== FALSE && $account->status == 0) {
+      user_save($account, array('status' => 1));
+    }
+  }
 }
 
 /**
  * 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' => (int)$uid));
+    // Skip blocking user if they are already blocked.
+    if ($account !== FALSE && $account->status == 1) {
+      user_save($account, array('status' => 0));
+    }
+  }
 }
 
 /**
  * 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' => (int)$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 ($account !== FALSE && !isset($account->roles[$rid])) {
+          $roles = $account->roles + array($rid => $role_name);
+          user_save($account, array('roles' => $roles));
         }
       }
       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' => (int)$uid));
+        // Skip removing the role from the user if they already don't have it.
+        if ($account !== FALSE && isset($account->roles[$rid])) {
+          $roles = array_diff($account->roles, array($rid => $role_name));
+          user_save($account, array('roles' => $roles));
+        }
       }
       break;
   }
