Drupal 7.12
User_Stats 1.x-dev

Posts count reset to "1" after user login, only "Reset counters" help for next user login. Cron, clear cache not helps.

Comments

christian death’s picture

I have the same problem.

samgreco’s picture

I am seeing this also. Seems that on mine it is completely unpredictable. I currently have one user showing all of their posts and everyone else showing 1.

Sometimes clearing the caches fixes it, sometimes not. Sometimes Cron fixes it.

theshanergy’s picture

Has anyone found a fix for this? I took a browse through the module but couldn't find the culprit. Same issue as described.

Sifro’s picture

@samgreco, i had the same issues, but it was because user_stats doesn't work retroactively.. may it be your case?

EDIT: wait, i've just discovered it DOES work retroactively... i just dont know how i made it work. Try going to the user_stats setting page, and set the content types you need to count, also try increasing the limit of users to update per cron run... then clear cache, runcron, and see what happens

samgreco’s picture

@Sifro - I seem to have it working using your technique. But I swear I've been here before :) I'll monitor it and see if it continues working.

Sifro’s picture

glad it worked, so now let's keep monitoring because i don't feel safe yet :)

samgreco’s picture

So many users are showing 1 again. Although not all???

samgreco’s picture

So I added a content type and changed the number of users to scan during a cron run. Saved it. Cleared the cache. And ran cron. Everything is good again.

So it seems that settings must change in order to "fix" it.

blischalk’s picture

This may or not be the solution to the problem described in this issue but it worked for us.

I believe there is a bug in this module on lines 121 and 891 in the file user_stats.module

Line 891 in function user_stats_post_count_update():

$count = (user_stats_get_stats('post_count', $uid) + 1);

Line 121 in function user_stats_get_stats():
if (!user_access('View statistics')) {
  return FALSE;
}

Here is the scenario:
If a user doesn't have the permission to view a statistic, when user_stats_post_count_update calls user_stats_get_stats on line 891 it returns false because line 121 checks the users permissions and the user doesn't have the permission to view the statistics. Since this function is returning false instead of a real post_count, the expression false + 1 is evaluating to 1 which sets the post count to 1 for that user. For the user it doesn't matter because they can't see the statistics anyway but other users who have the permissions to view statistics will see the now inaccurate post count.

The temporary solution would be to:
- Make sure that users who should have accurate statistics have the ability to view the statistics as well.
- Reset statistics which should start tracking the statistics properly.

Triskelion’s picture

This is the danger of using a single function for two different purposes. On the one hand, it is to retrieve statistics to show to the user (view), and on the other hand, to retrieve a number to be incremented (update).

To correct, add an operation parameter to the function at line 97:

function user_stats_get_stats($type, $uid, $op='view') {

Add the operation parameter to the test at line 121:

    if (!user_access('View statistics') && $op=='view') {

and change the call at line 891 to:

        $count = (user_stats_get_stats('post_count', $uid, 'update') + 1);

The issue is not related to user permissions, but rather to the intended operation.