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...
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | fix_get_current_for_custom_default.patch | 904 bytes | berdir |
Comments
Comment #1
kbahey commentedThe current code in the -dev version is like this:
And that works normally.
Don't see what the problem is ...
Comment #2
acidrob commentedThe 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
Comment #3
acidrob commentedPerhaps
should be
Comment #4
kbahey commentedPlease 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.
Comment #5
berdirAttaching 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.
Comment #6
manuel.adanClosing this as outdated, 6.x version is no longer maintained.