Introduce a log_stat function. Also adds an example of how it could be used by incrementing listing page views.
Note:
I decided to do the stat update in one go by using ON DUPLICATE UPDATE. In order for duplicate to trigger, I introduced a unique index and I changed the stat table definition a bit for this. LMK if the new structure seems reasonable.
I crammed it all into the Stats class. They should probably live in separate classes eventually, but I think it is convenient for reading all the changes in one go and for not overengineering without reason.
The DB changes have testing implications. You probs need to drop the stats table entirely. dBdelta does not do a good job with handling e.g. the default field change or the unique index change.
TBD: Should we drop the other index entirely?
Testing Instructions
First off, drop the existing stats table.
deactivate/activate Job Manager.
Check that the db schema has a unique index and post_id defaults to 0 now.
Visit a generic page. No stats entries.
Visit a job listing page. Stats entry.
Refresh. Stat increments.
Visit different listing. New stat entry,
Release Notes
N/A
New or Updated Hooks and Templates
N/A
Deprecated Code
N/A
Screenshot / Video
Plugin build for 074eccb57c9466bc86b138ce7ea9207f9260f11b
Fixes #2716
Changes Proposed in this Pull Request
Note:
I decided to do the stat update in one go by using
ON DUPLICATE UPDATE
. In order for duplicate to trigger, I introduced a unique index and I changed the stat table definition a bit for this. LMK if the new structure seems reasonable.I crammed it all into the Stats class. They should probably live in separate classes eventually, but I think it is convenient for reading all the changes in one go and for not overengineering without reason.
The DB changes have testing implications. You probs need to drop the stats table entirely. dBdelta does not do a good job with handling e.g. the default field change or the unique index change.
TBD: Should we drop the other index entirely?
Testing Instructions
Release Notes
New or Updated Hooks and Templates
Deprecated Code
Screenshot / Video