original_string: public function moveUsersToAlternativeGroups($userIdGroupIdMapping)
      {
          $affectedUsers = 0;
          $affectedGroups = [];
          foreach ($userIdGroupIdMapping as $userId => $groupId) {
              $affectedUsers += $this->UsersGroups->updateAll([
                  'group_id' => $groupId
              ], [
                  'user_id' => $userId
              ]);
              if (!in_array($groupId, $affectedGroups)) {
                  $affectedGroups[] = $groupId;
              }
          }
          if ($affectedUsers > 0 && !empty($affectedGroups)) {
              $this->updateUserCount($affectedGroups);
          }
          return $affectedUsers;
      }
code: public function moveUsersToAlternativeGroups($userIdGroupIdMapping)
      {
          $affectedUsers = 0;
          $affectedGroups = [];
          foreach ($userIdGroupIdMapping as $userId => $groupId) {
              $affectedUsers += $this->UsersGroups->updateAll([
                  'group_id' => $groupId
              ], [
                  'user_id' => $userId
              ]);
              if (!in_array($groupId, $affectedGroups)) {
                  $affectedGroups[] = $groupId;
              }
          }
          if ($affectedUsers > 0 && !empty($affectedGroups)) {
              $this->updateUserCount($affectedGroups);
          }
          return $affectedUsers;
      }
code_tokens: public function moveUsersToAlternativeGroups ( $ userIdGroupIdMapping ) { $ affectedUsers = 0 ; $ affectedGroups = [ ] ; foreach ( $ userIdGroupIdMapping as $ userId => $ groupId ) { $ affectedUsers += $ this -> UsersGroups -> updateAll ( [ 'group_id' => $ groupId ] , [ 'user_id' => $ userId ] ) ; if ( ! in_array ( $ groupId , $ affectedGroups ) ) { $ affectedGroups [ ] = $ groupId ; } } if ( $ affectedUsers > 0 && ! empty ( $ affectedGroups ) ) { $ this -> updateUserCount ( $ affectedGroups ) ; } return $ affectedUsers ; }
docstring: Assign users to new groups.
  
  @param array $userIdGroupIdMapping A mapping of user ids to their new group ids.
  @return int number of affected user rows
docstring_tokens: Assign users to new groups .