WooCommerce Services is a feature plugin that integrates hosted services into WooCommerce (3.0+), and currently includes automated tax rates and the ability to purchase and print USPS shipping labels.
This PR replaces the task queue with a state machine to drive the migration process. This PR will remember where the last "stopped" state is should an error occur. This allows the user to continue where they left off. For example, if the user installed the plugin but failed to activate it, the next time they run the migration, it will start from "activating" instead of the beginning.
Related issue(s)
N/A
Steps to test
Happy path - test the full migration
Go to woocommerce-services/classes/class-wc-connect-service-settings-store.php and replace the following is_eligible_for_migration function. This function decides if the modal should popup or not
Make sure you have "WooCommerce Shipping" and "WooCommerce Tax" in your plugins folder. We can't test the "install" part because they aren't part of dotorg yet.
Go to any order page with WCS&T enabled, click the WCS&T "Create shipping label" red button,
Click "Update now"
It should install, activate Woo Shipping & Woo Tax, deactivate WCS&T, and redirect you to the plugins page.
[Optional] Check DB's wp_options table, wc_connect_options should have the value ..."wcshipping_migration_state";i:12;} appended at the end. Key thing here is 12 is the "done state".
Test 404 on install and activate, fix the issue, then continue
Repeat Step 1 to 3 above. Refresh the page so it deletes the wcshipping_migration_state option.
Now, comment out WC_Connect_Options::delete_option( 'wcshipping_migration_state' ); from the happy path step 1). In this test, we want to keep wcshipping_migration_state so we can test the exceptions.
What we want to test here is to mimic a 404 errors downloading from dotorg. Or some API errors during activation. Here, we will test by tripping the circuit breaker at the wc-admin/plugins/install and wc-admin/plugins/activate API calls. The goal is to test if the migration can continue where it last failed.
npm run start. Open up client/components/migration/migration-runner.js. Append 2 to the API URL so they fail and throw 404. Change the following
You should see this in the console because /install2 failed
The migration_state value should be 5 because it failed at installation.
5.1 [optional] Check DB wp_options, wc_connect_options should have value appended at the end "wcshipping_migration_state";i:5;}.
Now, fix the issue by changing /install2 back to install. Refresh the page. install should work, and activate will now fail. The installation should pick up from the "install" step.
Confirm it starts from "install" and failed at "activate". The migration_state should be 7.
7.1. [optional] Check DB wp_options, wc_connect_options should have value appended at the end "wcshipping_migration_state";i:7;}.
Now, fix the activate2 to activate. The migration should pick up from state 7 and go through the whole migration.
[optional] Check DB wp_options, wc_connect_options should have value appended at the end "wcshipping_migration_state";i:12;}.
You should be on the plugins page http://localhost/wp-admin/plugins.php?plugin_status=all&paged=1&s. Confirm the WCS&T is deactivated, and Woo Shipping and Woo Tax are enabled.
👋 Hi @Ferdev I think I addressed all the feedback on the PR, let me know what you think! Please feel free to merge for me if it looks good and if I am AFK.
Description
This PR replaces the task queue with a state machine to drive the migration process. This PR will remember where the last "stopped" state is should an error occur. This allows the user to continue where they left off. For example, if the user installed the plugin but failed to activate it, the next time they run the migration, it will start from "activating" instead of the beginning.
Related issue(s)
N/A
Steps to test
Happy path - test the full migration
Go to
woocommerce-services/classes/class-wc-connect-service-settings-store.php
and replace the followingis_eligible_for_migration
function. This function decides if the modal should popup or notwp_options
table,wc_connect_options
should have the value..."wcshipping_migration_state";i:12;}
appended at the end. Key thing here is12
is the "done state".Test 404 on install and activate, fix the issue, then continue
wcshipping_migration_state
option.WC_Connect_Options::delete_option( 'wcshipping_migration_state' );
from the happy path step 1). In this test, we want to keepwcshipping_migration_state
so we can test the exceptions.What we want to test here is to mimic a 404 errors downloading from dotorg. Or some API errors during activation. Here, we will test by tripping the circuit breaker at the
wc-admin/plugins/install
andwc-admin/plugins/activate
API calls. The goal is to test if the migration can continue where it last failed.npm run start
. Open upclient/components/migration/migration-runner.js
. Append2
to the API URL so they fail and throw404
. Change the followingfetch( getBaseURL() + 'wc-admin/plugins/install', {
tofetch( getBaseURL() + 'wc-admin/plugins/install2', {
fetch( getBaseURL() + 'wc-admin/plugins/activate', {
tofetch( getBaseURL() + 'wc-admin/plugins/activate2', {
/install2
failed Themigration_state
value should be5
because it failed at installation. 5.1 [optional] Check DBwp_options
,wc_connect_options
should have value appended at the end"wcshipping_migration_state";i:5;}
./install2
back toinstall
. Refresh the page.install
should work, and activate will now fail. The installation should pick up from the "install" step.migration_state
should be 7. 7.1. [optional] Check DBwp_options
,wc_connect_options
should have value appended at the end"wcshipping_migration_state";i:7;}
.activate2
toactivate
. The migration should pick up from state7
and go through the whole migration.wp_options
,wc_connect_options
should have value appended at the end"wcshipping_migration_state";i:12;}
.http://localhost/wp-admin/plugins.php?plugin_status=all&paged=1&s
. Confirm the WCS&T is deactivated, and Woo Shipping and Woo Tax are enabled.Checklist
changelog.txt
entry addedreadme.txt
entry added