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 migration to move incorrectly stored payment token IDS to HPOS tables #39724

Merged
merged 2 commits into from Aug 14, 2023

Conversation

vedanshujain
Copy link
Contributor

@vedanshujain vedanshujain commented Aug 14, 2023

Submission Review Guidelines:

Changes proposed in this Pull Request:

This is a follow-up from #39381 and adds a migration to move over _payments_token meta to the order meta table. Note that we already have a "hot migration" in place, i.e. every time we get payment token meta, we also check the post meta table if the orders table is empty, so migration being complete should not be a prerequisite for orders payment tokens to work.

How to test the changes in this Pull Request:

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

Since nothing uses payment token in vanilla WooCommerce, we will be using CLI to run this migration.

  1. Set HPOS to Authoritative and sync to off. Switch to WC 8.0, and then open the wp shell by running wp shell and run following commands:
/ Let's create a new order first and save it. Note the order ID, let's say its ORDER_ID
$order = wc_create_order();
$order->save();

// Add some payment token for this order.
$token = new WC_Payment_Token_ECheck();
$token->set_last4( 1234 );
$token->set_token( time() );
$token->save();

// Add the token to order
$order->add_payment_token( $token );
  1. Make sure you note down the ORDER_ID of this newly created order.
  2. Close the shell and switch over to WC 8.1 (or WC dev build that includes this PR).
  3. Set the WooCommerce version into the database to a lower version, so that DB update gets triggered like so: wp option update woocommerce_version 8.0.0
  4. Refresh any admin page in WC, you should be prompted to do a DB update. Run the migration from the UX and wait for it to complete.
  5. Verify that the above token is stored in order meta table, by running the following SQL query:
wp db query "SELECT * FROM wp_wc_orders_meta WHERE order_id = ORDER_ID and meta_key = '_payment_tokens';"

You should see a serialized value, for example, if the value when getting from code is [1], then the serialized will be a:1:{i:0;i:1;}.

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 Aug 14, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 14, 2023

Test Results Summary

Commit SHA: d5e2c58

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 50s
E2E Tests1950015021024m 48s

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.

@vedanshujain vedanshujain marked this pull request as ready for review August 14, 2023 12:51
@github-actions
Copy link
Contributor

Hi @coreymckrill,

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

Copy link
Collaborator

@coreymckrill coreymckrill left a comment

Choose a reason for hiding this comment

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

👍 Works as described in testing instructions.

I also tried creating two separate order/payment token pairs and switching the batch size of the migration script to 1 to make sure it would, in fact, process multiple batches if necessary. It did 😄

@coreymckrill coreymckrill added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Aug 14, 2023
@tammullen tammullen 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 Aug 14, 2023
@tammullen tammullen merged commit 1566416 into trunk Aug 14, 2023
30 checks passed
@tammullen tammullen deleted the fix/35612-migration branch August 14, 2023 20:31
@github-actions github-actions bot added this to the 8.1.0 milestone Aug 14, 2023
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.

None yet

3 participants