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

Allow WC Shipping to use larger migration state machine enums #2804

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions classes/class-wc-connect-service-settings-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,14 +617,20 @@ public function get_package_lookup() {
}

public function is_eligible_for_migration() {
$migration_state = intval( get_option( 'wcshipping_migration_state', 0 ) );

// If the migration state is greater than "COMPLETED", then we can assume that the next part of the migration
// state is being handled by WooCommerce Shipping.
if ( $migration_state > WC_Connect_WCST_To_WCShipping_Migration_State_Enum::COMPLETED ) {
return false;
}

$migration_dismissed = false;
if ( isset( $_COOKIE[ WC_Connect_Loader::MIGRATION_DISMISSAL_COOKIE_KEY ] ) && (int) $_COOKIE[ WC_Connect_Loader::MIGRATION_DISMISSAL_COOKIE_KEY ] === 1 ) {
$migration_dismissed = true;
}

$migration_state = get_option( 'wcshipping_migration_state' );

$migration_pending = ! $migration_state || WC_Connect_WCST_To_WCShipping_Migration_State_Enum::COMPLETED !== intval( $migration_state );
$migration_pending = ! $migration_state || WC_Connect_WCST_To_WCShipping_Migration_State_Enum::COMPLETED !== $migration_state;
$migration_enabled = $this->service_schemas_store->is_wcship_wctax_migration_enabled();

return $migration_pending && $migration_enabled && ! $migration_dismissed;
Expand Down
21 changes: 17 additions & 4 deletions classes/class-wc-rest-connect-migration-flag-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,31 @@ public function set_tracks( $tracks ) {
public function post( $request ) {
$params = $request->get_json_params();
$migration_state = intval( $params['migration_state'] );

// If the migration state is greater than "COMPLETED", then we can assume that the next part of the migration
// state is being handled by WooCommerce Shipping.
// This shouldn't be necessary since our migration shouldn't be displayed to begin with, but we're adding
// support for it, just in case.
if ( $migration_state > WC_Connect_WCST_To_WCShipping_Migration_State_Enum::COMPLETED ) {
return new WP_REST_Response(
array(
'result' => __( 'WooCommerce Shipping has taken over the migration process.', 'woocommerce-services' ),
),
200
);
}

if ( ! WC_Connect_WCST_To_WCShipping_Migration_State_Enum::is_valid_value( $migration_state ) ) {
$error = new WP_Error(
return new WP_Error(
'invalid_migration_state',
__( 'Invalid migration state. Can not update migration state.', 'woocommerce-services' ),
array( 'status' => 400 )
);
return $error;
}

$existing_migration_state = get_option( 'wcshipping_migration_state' );
if ( $existing_migration_state && intval( $existing_migration_state ) === $migration_state ) {
return new WP_REST_Response( array( 'result' => 'Migration flag is the same, no changes needed.' ), 304 );
return new WP_REST_Response( array( 'result' => __( 'Migration flag is the same, no changes needed.', 'woocommerce-services' ) ), 304 );
}

$result = update_option( 'wcshipping_migration_state', $migration_state );
Expand All @@ -61,7 +74,7 @@ public function post( $request ) {
)
);

return new WP_REST_Response( array( 'result' => 'Migration flag updated successfully.' ), 200 );
return new WP_REST_Response( array( 'result' => __( 'Migration flag updated successfully.', 'woocommerce-services' ) ), 200 );
}

$error = new WP_Error(
Expand Down
Loading