The function to retrieve userpoints checks to see if the tid is not null, but that will also include when tid is 0 (when your trying to get uncategorized points), and will substutite the tid for the default category. If your default cat is not uncategorised - you will get incorrect values.

perhaps change the default param from null to -1, and check to if ($tid < 0)

function userpoints_get_current_points($uid = NULL, $tid = -1) {
if (!$uid) {
global $user;
$uid = $user->uid;
}
if ($tid < 0) {
$tid = userpoints_get_default_tid();
}
elseif ($tid == 'all') {
return (int)db_result(db_query('SELECT SUM(points) FROM {userpoints} WHERE uid = %d', $uid));
}
return (int)db_result(db_query('SELECT points FROM {userpoints} WHERE uid = %d AND tid = %d', $uid, $tid));
}

This is what Ive done as a temporary fix at least...

CommentFileSizeAuthor
#5 fix_get_current_for_custom_default.patch904 bytesberdir

Comments

kbahey’s picture

Status: Active » Postponed (maintainer needs more info)

The current code in the -dev version is like this:

function userpoints_get_current_points($uid = NULL, $tid = NULL) {
  ...
  if (!$tid) {
    $tid = userpoints_get_default_tid();
  }

And that works normally.

Don't see what the problem is ...

acidrob’s picture

The problem is when calling that function with a value $tid = 0 ,this value is used for uncategorized.
Uncategorized is not my default category, but the current logic will replace $tid=0 to $tid=defaultcat
So when I request the value of uncategorized I get the value for the default catageory instead (a different category with a different score!) - could be the root cause of a few bugs

acidrob’s picture

Perhaps

function userpoints_get_current_points($uid = NULL, $tid = NULL) {
  ...
  if (!$tid) {
    $tid = userpoints_get_default_tid();
  }

should be

function userpoints_get_current_points($uid = NULL, $tid = NULL) {
  ...
  if (!is_numeric($tid)) {
    $tid = userpoints_get_default_tid();
  }
kbahey’s picture

Please try that on your site and test it. Tell us how you tested it and what you found out.

Also, if someone else can test this case after a change, please do so and report back.

If all is well for all testers, I will change it.

berdir’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new904 bytes

Attaching a patch, this has already been identified and fixed in D7.

Note that the second condition also needs to be updated to be type-safe.

manuel.adan’s picture

Component: Code: userpoints API » Code: userpoints
Issue summary: View changes
Status: Needs review » Closed (outdated)

Closing this as outdated, 6.x version is no longer maintained.