Skip to content
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 wc hpos backfill tool to backfill from/to either datastore #44281

Merged
merged 12 commits into from Feb 15, 2024

Conversation

jorgeatorres
Copy link
Member

@jorgeatorres jorgeatorres commented Feb 1, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

This PR adds a new CLI tool wp hpos backfill that can be used to backfill orders from either the HPOS or CPT datastore, regardless of what the current datastore is.
This can be used to resolve situations where a given order has correct data in either table but the merchant can't change datastores or the sync process would overwrite other orders.

Closes #41909.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Go to WC > Settings > Advanced > Features and make sure HPOS is set as datastore and compat mode is disabled.
  2. If your site doesn't have any orders, create at least one in WC > Orders > Add order.
  3. Open any order (in the admin) and take note of its ID.
  4. Go to Custom Fields and add a custom field by specifying a name (say, <meta_key>) and value and clicking "Add Custom Field" or saving the order.
  5. Confirm that the backup post doesn't have this metadata (since compat mode is disabled) by running wp post meta list <order_id> and confirming the list doesn't include this new meta / is empty.
  6. Run wp wc hpos backfill <order_id> --from=hpos --to=posts.
  7. Run wp post meta list <order_id> and confirm that now all the order metadata appears, including the metadata you manually added.
  8. Directly modify the post metadata by running wp post meta update <order_id> <meta_key> <any_other_meta_value>.
  9. Confirm that this metadata is not yet in the HPOS tables by re-opening this order in the admin and verifying that the Custom Fields metabox still lists the original value.
  10. Run wp wc hpos backfill <order_id> --from=posts --to=hpos to backfill from posts to HPOS.
  11. Refresh the order edit screen / re-open the order for editing in the admin, and confirm that the Custom Fields metabox now lists the metadata we manually added to the post (in step 8).

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Feb 1, 2024
Copy link
Contributor

github-actions bot commented Feb 1, 2024

Test Results Summary

Commit SHA: 3520f6d

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 37s
E2E Tests31800303217m 7s

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.

@jorgeatorres jorgeatorres requested review from a team and Konamiman and removed request for a team February 12, 2024 23:42
Copy link
Contributor

Hi @Konamiman,

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:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

* <id>
* :The ID of the order.
*
* [--from=<hpos|posts>]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be coherent with how multiple choice arguments are usually specified in the help of command line tools it could be:

--from={hpos|posts}

(angle brackets usually indicate non-literal values that need to be replaced, like in <order id>)

And the same with --to.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually got me thinking what the "correct" format should be. I agree with you that the braces seem to better indicate the options, but apparently WP-CLI expects arguments in a specific format (https://make.wordpress.org/cli/handbook/references/documentation-standards/#command-parameter-description) and so I changed the documentation to match that. This actually allows WP-CLI to validate args before the command runs.

I also made the --from and --to arguments mandatory with no default, to make things more explicit and prevent accidental overwriting of orders.

@Konamiman
Copy link
Contributor

Looks good, I just added a couple of comments regarding the arguments syntax used in the command help.

@jorgeatorres
Copy link
Member Author

Hey @Konamiman!

I've made some changes based on your feedback. Please take another look at your leisure! Thanks for the review!

@jorgeatorres jorgeatorres merged commit f79bf3a into trunk Feb 15, 2024
38 checks passed
@jorgeatorres jorgeatorres deleted the hpos/41909 branch February 15, 2024 16:13
@github-actions github-actions bot added this to the 8.7.0 milestone Feb 15, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Feb 15, 2024
@Stojdza Stojdza added needs: internal testing Indicates if the PR requires further testing conducted by Solaris status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: internal testing Indicates if the PR requires further testing conducted by Solaris plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CLI] Allow specifying the datastore to sync from/to in the sync command
3 participants