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
Add HPOS CLI tool to compare an order between datastores #43173
Conversation
Test Results SummaryCommit SHA: e12f483
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
67c1c42
to
e12f483
Compare
Hi @lsinger, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
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.
Tests well -- a very nice and slick experience. Very cool!
Left a few notes, but no blockers in there. LGTM! 🚢
$val2 = get_post_meta( $order_id, $key, true ); | ||
} | ||
|
||
if ( $val1 != $val2 ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
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.
We might want to add a note here why it's absolutely necessary to allow loose comparison.
plugins/woocommerce/src/Internal/DataStores/Orders/LegacyDataHandler.php
Show resolved
Hide resolved
$data_store_wrapper = \WC_Data_Store::load( 'order' ); | ||
|
||
// Bind $data_store to our WC_Data_Store. | ||
( function ( $data_store ) { |
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.
Interesting pattern! Could you explain why this was the best (only?) option here? Just for my personal understanding.
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.
Given WC_Order
is a WC_Data
child class, the datastore in objects of this type has access protected
so we can't directly change it from the outside.
To make things worse, that data_store
variable is not directly an instance of the HPOS (or CPT) datastore, but of WC_Data_Store
, which stores the details in a private
variables.
WC_Data_Store
is meant to be a singleton so what we could do here is add public methods to WC_Data
to change its backing datastore, but that's not without its own set of problems (what happens when reading or saving data if you change the backing datastore in an object mid execution?) and I guess we don't want to increase API surface at this moment.
Now, even though datastores have a read()
method that receives a "blank" object, this method's name is a bit misleading because this will not set the backing datastore on the blank object nor read all properties.
Metadata is read via $this->data_store->read_meta()
which would use the "default" datastore unless we change it "somehow".
This ugly hack above is that "somehow" 😓. I believe the whole CRUD layer and datastore/object interactions in particular would benefit from a revision, but 🤷.
(Sorry if this is even more confusing)
Submission Review Guidelines:
Changes proposed in this Pull Request:
This PR adds a new CLI tool
wp wc hpos diff
which can be used to compare an order between datastores to see which properties or metadata differ. It's slightly more user friendly thanwp wc verify_cot_data
for individual orders.This PR also adds a
wp wc hpos status
tool that displays current values of various HPOS variables, such as whether it is enabled or not, or how many orders need to be synced/etc.Closes #41908.
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
wp wc hpos diff <order_id>
. Output should be "Success: No differences found.".wp wc hpos diff <order_id>
again. This time the output should look something like this (depending on the changes made in the previous step):wp wc cot sync
to sync orders between datastores.wp wc hpos diff <order_id>
again and confirm, once more, that output is "Success: No differences found.".wp wc hpos status
to take a look at your HPOS variables. It should correctly reflect whether HPOS is enabled or not and other bits of information.Changelog entry
Significance
Type
Message
Comment