Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
christian death CreditAttribution: christian death commentedI have the same problem.
Comment #2
samgreco CreditAttribution: samgreco commentedI 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.
Comment #3
theshanergy CreditAttribution: theshanergy commentedHas anyone found a fix for this? I took a browse through the module but couldn't find the culprit. Same issue as described.
Comment #4
Sifro CreditAttribution: Sifro commented@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
Comment #5
samgreco CreditAttribution: samgreco commented@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.
Comment #6
Sifro CreditAttribution: Sifro commentedglad it worked, so now let's keep monitoring because i don't feel safe yet :)
Comment #7
samgreco CreditAttribution: samgreco commentedSo many users are showing 1 again. Although not all???
Comment #8
samgreco CreditAttribution: samgreco commentedSo 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.
Comment #9
blischalk CreditAttribution: blischalk commentedThis 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
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.
Comment #10
Triskelion CreditAttribution: Triskelion commentedThis 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:
Add the operation parameter to the test at line 121:
and change the call at line 891 to:
The issue is not related to user permissions, but rather to the intended operation.