-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add migration to fix incorrect product review count. #28814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Also refactors get_review_count_for_product to use the new method so that we only would have to maintain one method.
roykho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested well for me. I had to checkout release/4.8 and followed the steps in the original issue to reproduce it. Then I checkout this PR and followed the testing steps and it fixed the arbitrary review count 9999 to the correct count in the product frontend.
Thanks for including the test cases. I just left small comments.
includes/class-wc-comments.php
Outdated
| $product_id_string = implode( "','", array_map( 'esc_sql', $product_ids ) ); | ||
|
|
||
| $review_counts = $wpdb->get_results( | ||
| // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come we're bypassing prepare here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because of $product_id_string which we were expanding for IN clause. I thought this is the standard way to use when doing interpolation for IN clause.
But after your comment, I looked in detail and see how WP core is doing it, and found this reference: https://github.com/pantheon-systems/wordpress-network/blob/master/wp-includes/class-wp-meta-query.php#L639.
This approach still ignores phpcs, but does not bypass prepare so I have changed the code to use this approach in 9f9475a. Let me know if this makes sense.
1: Use placeholder to be able to use wpdb->prepare for IN query. Update version number.
roykho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
All Submissions:
Changes proposed in this Pull Request:
In #28624 we fixed the root cause for $27688, however, we still needed a migration to fix the product review counts. This PR adds that migration, to fix the counts, we loop over all meta props with keys
_wc_review_countand update them if they are incorrect and post belongs to a product.Closes #27688.
How to test the changes in this Pull Request:
Other information:
Changelog entry