HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
post counts in side panel not updating - Vanilla 3.2
I'm using Vanilla 3.2 on Linux, after having migrated my forum several month s ago from v2.2 on Windows to v2.8.3 on Linux, and then successive updates to 3.2 on Linux, all with no problems. Overall things are fine, though I recently realized that the post counts next to each of my categories shown in the side panel are not updating when a new post is created.
If I visit
/dba/counts, and update all the options shown there, the post counts are updated correctly, but then any subsequent new discussion created again does not update the appropriate Category count.
Suggestions at what I should be looking at to fix? Thanks in advance.
You have to start in /applications/vanilla/models/class.discussionmodel.php
Look at line 2283-2290. From what I can tell, it is always CategoryModel->incrementLastDiscussion() that is called.
I don't see anything in there which looks critical, but you would have to debug what is going wrong with your installation. It would be great if you can share what you find out since that is something which is asked more often.
Thanks very much for your response. I took a look at that section of the code in class.discussionmodel.php, and in turn within class.categorymodel.php , at that incrementLastDiscussion() method. I can't see anything obvious there, and also when looking at my database contents within the GDN_Category and GDN_Discussion tables. Each discussion has a DiscussionID, each category has a CategoryID.
I'm not an expert in this stuff, but nothing screamed "problem" to me...
No, there is nothing obvious. You will have to debug that code. If you are not able and you are willing to share your server credentials with me and grant me admin access I'll try to look at what is going on. Here is what I would do:
Thanks very much for that offer R_J - I'll PM you.
@dnigrin was so kind to allow me to debug the problem in his forum, thanks for that!
Technically spoken the problem arises because some method expects the CategoryID to be of type integer when a string is passed. Because of the type mismatch, the column CountAllDiscussions isn't increased while it should. The code is in line 165 of CategoryCollection->get():
I fixed it, but I'm not sure why there is a difference between your installation and mine. Technically spoken the problem is that the CategoryID is passed to a function as a string when an integer is expected. The code is in class.categorycollection.php.
is_intis used in line 168 but if you replace that with
is_numeric, the code works as expected.
I try to find out why the CategoryID is passed as a string because I think exchanging the functions in the CategoryCollection is only fixing a symptom and not the problem.
Thank you @R_J !!!
All I can think of re: the problem you found is that I mentioned in the first post: this install is a migrated one from a previous Windows install - perhaps some data types in the database got converted from int to string when I exported the database from my Windows install, and then re-imported into my current Linux one?
I did have a database related issue that I needed to correct initially, having to do with table name capitalization (see this thread: https://open.vanillaforums.com/discussion/37303/migrate-from-v2-2-windows-to-v2-8-3-linux ), but otherwise things were smooth.
I have run "describe GDN_Category" and the column was of type int, but yes, sounds as if that migration could be the reason.
When I save a discussion to GDN_Discussion the CategoryID (type before save: string) is written to the GDN_Discussion table and if I read the discussion from the database, the CategoryID is of type integer, just as expected.
On your installation the retrieved CategoryID is of type string which has been the reason for that problem. But there might be other glitches based on the same problem.
Thanks @R_J, understood.
That problem has been solved before: https://open.vanillaforums.com/discussion/35885/post-count-not-updating
Oh wow, you're right! And as outlined in that thread, my PDO installation is not using mysqlnd, so that was my problem as well.