Max Points is being calculated incorrectly.

Here is the current code in userpoints.module (1.44.2.14):

304 // Calculate the current point
305 $current_points = (int)$points + userpoints_get_current_points($uid);
306
307 // Check if user has earned points
308 if ($points > 0) {
309 // Set the max_points to be the current max points, plus whatever earned in this transaction
310 $max_points = db_result(db_query('SELECT max_points FROM {userpoints} WHERE uid = %d', $uid));
311 $max_points = $current_points + (int)$max_points;
312 }

Line 311 should read instead:

$max_points = (int)$points + (int)$max_points;

The way it is written now, the max_points at least double every time the table is updated.

Comments

jredding’s picture

Assigned: Unassigned » jredding
Status: Active » Closed (duplicate)

This has been fixed in version 3 and is a duplicate issue.

beltofte’s picture

Status: Closed (duplicate) » Active

I was implementing the userpoints module in a gallery module where each node has a gallery, and the users recieve points for uploading an image to a gallery/node. And if the uploaded image is deleted again, then the user should loose the earned points.

But when you give a user negative points, the max_points is not updated correct.

In userpoints.module v. 1.44.2.13 the max_points is set to zero, when trying to add a negative point to a user. Line 308 should be changed to:

if ($points != 0) {

And i userpoints.module v. 1.44.2.14.2.31 the max_points is just not updated. Line 662 should be changed to:

if ($params['points'] != 0) {

I am using the old version and therefore i posted the fix for that version also.

jredding’s picture

Status: Active » Fixed

Max points is designed to show the maximum points the user has received (in history). If you change this line then max points would reflect regular points as max points would move UP and DOWN in line with the point grants.

You're fix should not and will not be implemented as it breaks max points.

I'm changing the status back to fixed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.