All Good Things Must Come To An End

As you all know, I have been doing WordPress plugins and supporting it for the past 6 years. These 6 years of my life, I have been through my polytechnic education, my national service as well as my university education.

I just graduated from university in December 2009 and have been looking for full-time jobs. I am offered a full-time job and will be starting work on 1st February 2010.

I regret to say that I am NOT ABLE to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

However, I WILL still update my plugins whenever I can and you still can report bugs to me via email and I will try to fix it.


Author Topic: How to update stats after an edit  (Read 2242 times)

0 Members and 1 Guest are viewing this topic.

Offline gerryg

  • Newbie
  • *
  • Posts: 14
    • View Profile
How to update stats after an edit
« on: 15 April 2009, 04:30 »
WP 2.7.1 PHP 5.2.4 WP-STATS plugin 2.40
When I create a new blog and publish, stats are fine. But if I edit and change the category for that post, the stats now show a broken link and bring up an empty page. Updating permalinks no change. I imagine you can't track all changes, so is there a way to refresh the wp-stats?

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: How to update stats after an edit
« Reply #1 on: 15 April 2009, 04:38 »
You are talking about WordPress Stats or WP-Stats? The links are all real time and not cache.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline gerryg

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to update stats after an edit
« Reply #2 on: 15 April 2009, 04:49 »
This was from the Top Ten Recent Stats after clicking wp-stats. Just checked and all of them are now bad for the posts, showing pages 5 or 6. The recent comments below them are still working.

Offline gerryg

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to update stats after an edit
« Reply #3 on: 15 April 2009, 04:57 »
Further, the Ten Most/Highest Stats below do all work, even if listing the same item that is bad above. Other items below this also seem to work, so only the Top Ten Recent Stats - 10 Recent Posts do not work.

I know it worked right after I first published the post. I may have edited the others at some time.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: How to update stats after an edit
« Reply #4 on: 15 April 2009, 05:13 »
The link displayed is the new link or the old link? Did you try the date/time permalink?

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline gerryg

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to update stats after an edit
« Reply #5 on: 15 April 2009, 06:04 »
The bad links displayed show page 5 or 6, several duplicating. Actual pages should be around 320.
If I change permalinks to date/time from the default, it breaks everything in the blog.

Whatever you're using in "10 most commented posts" is working fine, but not in "10 recent posts" even for the same item.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: How to update stats after an edit
« Reply #6 on: 15 April 2009, 06:54 »
sorry but I don't get you and I can't reproduce the problem. I have a post and edit the category, change from "WordPress" to "Site" and I go to Top 10 recent post and I am able to display it without any problem.

To add, I don't see why changing categories of a post will cause permalink to break as they are not related at all. You may want to try it on a fresh copy of WP instead.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline gerryg

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to update stats after an edit
« Reply #7 on: 15 April 2009, 16:25 »
On permalinks not related to categories, agreed. I'll try this in another wp blog to check. Don't see any issue in your code or the wp supporting routines, but I'll run your query directly and see what comes back. It's either there or the fetch of the post body.

Thanks for looking. I'll get back if I find anything on your end.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: How to update stats after an edit
« Reply #8 on: 15 April 2009, 16:44 »
Yea please do, lol this is a mysterious problem

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline gerryg

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to update stats after an edit
« Reply #9 on: 21 April 2009, 18:25 »
Finally got back to looking at this. Had to setup eclipse/pdt/xdebug so I could see what's happening. Used brand new wordpress install adding only wp-stats. Added 4 posts and deleted the original. So, the post IDs are 2,3,4,5. Added one comment. No other changes. Using default permalinks.

For the 10 recent posts you show the right names but all have an ID = 1.

In wp-stats.php your query there is:
SELECT $wpdb->posts.*, $wpdb->users.* FROM $wpdb->posts LEFT JOIN $wpdb->users ON $wpdb->users.ID = $wpdb->posts.post_author WHERE user_activation_key = '' AND post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND post_password = '' ORDER  BY post_date DESC LIMIT $limit

It appears to me that your query returns the ID field from BOTH wp_posts and wp_users and the return mapping overwrites the wp_posts.ID with the wp_users.ID. Since I used the admin with an ID=1, that's where the "1" is coming from.

There may be other situations where this works, but I only just started with their code and don't know enough about it to say. However, this scenario does seem clear. To check, I REVERSED and made the select order in the query:
$wpdb->users.*, $wpdb->posts.*
and now you are showing the correct links.

Overall, your screen design and functionality are exactly what I needed, so this effort was well spent. Now, I need to check the db tables to see if I broke anything else by doing this:-)

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: How to update stats after an edit
« Reply #10 on: 22 April 2009, 05:03 »
How about try INNER JOIN instead of LEFT JOIN?

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline gerryg

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to update stats after an edit
« Reply #11 on: 22 April 2009, 16:49 »
You're nasty; I've been retired for 5 years and you're asking me to think too hard:-)
Well, in MySql INNER JOIN is equiv to CROSS JOIN. In this case, the only diff between that and LEFT JOIN is the handling of nulls in the mapping, if you had a post with no matching user. But that's a different issue. If we're sure one will always be there, the two are the same. If not and if you only want records that match the join criteria then INNER is better. But it won't effect the real issue here. Actually, it may or may not matter. Your WHERE has user_activation_key = '' and without digging further I don't know if that would match a null or not. If we're sure they maintain DB consistency between users and posts, it doesn't matter either way.

I haven't traced through the wordpress result mapping so I don't know if there may be other solutions. However, where you have:
  if($recentposts) {
    foreach ($recentposts as $post) {
I used the debugger on $post and I see only one ID field which is not table qualified. That implies that in any join of tables having an identical column name you will only receive the last such column, with the sequence determined by your SELECT statement.

So, one obvious solution is to explicitly name the columns in your SELECT for just the users table leaving all columns from the post table. That allows omitting the users.ID from the result table. Alternatively, just reverse the order as I did. I don't see any drawbacks to either approach.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: How to update stats after an edit
« Reply #12 on: 22 April 2009, 16:53 »
I can't explicitly name the columns as WP may need all of them, note that there is a $post global variable and these are pass to WordPress for handling.

You may be right on the null value, so I think a INNER JOIN will solve this problem as well. I think you could also change LEFT to RIGHT instead of changing the order as well.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline gerryg

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to update stats after an edit
« Reply #13 on: 22 April 2009, 17:02 »
On not explicitly giving the columns names, I agree with you. On nulls, the best thing is always to run the other way...

However, LEFT/RIGHT doesn't change the column order in the result table and that ordering is what caused the problem. If you see any issues with my first suggestion let me know what and I'll look for another approach.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: How to update stats after an edit
« Reply #14 on: 22 April 2009, 17:06 »
Sure, I am just figuring out why the order matters as subsequently all my queries started with $wpdb->posts first

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline gerryg

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to update stats after an edit
« Reply #15 on: 22 April 2009, 17:32 »
It matters in the return mapping from wp-db. That takes the results table and maps each value into a variable with the same name as the table column. So, posts.ID maps into $ID then you get users.ID which also maps into $ID, overwriting the previous value. It only happens when the results table has two columns with the same name. A direct sql query in phpmyadmin shows the results table with two ID columns.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: How to update stats after an edit
« Reply #16 on: 22 April 2009, 17:50 »
I see, thanks for the explaination. I have reverse the order to wpdb->users.* then $wpdb->posts.*

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline gerryg

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How to update stats after an edit
« Reply #17 on: 22 April 2009, 18:06 »
My pleasure. Just took a quick look at your other queries and don't see any similar issues. This was fun to fix and I'm going to do some minor tweaks to wp. If you happen on any more stubborn issues that need another set of "eyes" feel free to give me a shout via direct email. Us retired guys have to keep busy somehow.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: How to update stats after an edit
« Reply #18 on: 22 April 2009, 18:41 »
Sure thing, thank you so much!

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.