-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: delete old feature flags from DB (#9263)
Co-authored-by: Guilherme Pressutto <gpressutto5@gmail.com>
- Loading branch information
1 parent
6cd25af
commit 3a443f5
Showing
9 changed files
with
149 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: dev | ||
Comment: chore: delete old feature flags from DB | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
includes/migrations/class-erase-deprecated-flags-and-options.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Class Erase_Deprecated_Flags_And_Options | ||
* | ||
* @package WooCommerce\Payments | ||
*/ | ||
|
||
namespace WCPay\Migrations; | ||
|
||
defined( 'ABSPATH' ) || exit; | ||
|
||
/** | ||
* Class Erase_Deprecated_Flags_And_Options | ||
* | ||
* Clearing up all flags and options that are no longer in use. | ||
* | ||
* @since 8.1.0 | ||
*/ | ||
class Erase_Deprecated_Flags_And_Options { | ||
/** | ||
* Checks whether it's worth doing the migration. | ||
*/ | ||
public function maybe_migrate() { | ||
$previous_version = get_option( 'woocommerce_woocommerce_payments_version' ); | ||
// feel free to modify the version here to the next one, if you add a new flag to be deleted in the `migrate` method. | ||
if ( version_compare( '8.1.0', $previous_version, '>' ) ) { | ||
$this->migrate(); | ||
} | ||
} | ||
|
||
/** | ||
* Does the actual migration. | ||
*/ | ||
private function migrate() { | ||
// please update as necessary, when feature flags are removed. | ||
// you don't need to check for previous values or if the migration already ran in previous versions. | ||
// if the migration did already run, the operations below will just be noop. | ||
delete_option( '_wcpay_feature_progressive_onboarding' ); | ||
delete_option( '_wcpay_feature_client_secret_encryption' ); | ||
delete_option( '_wcpay_feature_allow_subscription_migrations' ); | ||
delete_option( '_wcpay_feature_custom_deposit_schedules' ); | ||
delete_option( '_wcpay_feature_account_overview_task_list' ); | ||
delete_option( '_wcpay_feature_account_overview' ); | ||
delete_option( '_wcpay_feature_sepa' ); | ||
delete_option( '_wcpay_feature_sofort' ); | ||
delete_option( '_wcpay_feature_giropay' ); | ||
delete_option( '_wcpay_feature_grouped_settings' ); | ||
delete_option( '_wcpay_feature_upe_settings_preview' ); | ||
delete_option( '_wcpay_feature_upe' ); | ||
delete_option( '_wcpay_feature_upe_split' ); | ||
delete_option( '_wcpay_feature_upe_deferred_intent' ); | ||
delete_option( '_wcpay_feature_dispute_on_transaction_page' ); | ||
delete_option( '_wcpay_feature_streamline_refunds' ); | ||
delete_option( 'wcpay_fraud_protection_settings_active' ); | ||
delete_option( '_wcpay_feature_mc_order_meta_helper' ); | ||
delete_option( '_wcpay_feature_pay_for_order_flow' ); | ||
delete_option( '_wcpay_feature_simplify_deposits_ui' ); | ||
delete_option( '_wcpay_fraud_protection_settings_enabled' ); | ||
delete_option( '_wcpay_feature_platform_checkout_subscriptions_enabled' ); | ||
delete_option( '_wcpay_feature_platform_checkout' ); | ||
delete_option( '_wcpay_feature_capital' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tests/unit/migrations/test-class-erase-deprecated-flags-and-options.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* Class Erase_Deprecated_Flags_And_Options_Test | ||
* | ||
* @package WooCommerce\Payments\Tests | ||
*/ | ||
|
||
namespace unit\migrations; | ||
|
||
use WCPay\Migrations\Erase_Deprecated_Flags_And_Options; | ||
use WCPAY_UnitTestCase; | ||
|
||
/** | ||
* WCPay\Migrations\Erase_Deprecated_Flags_And_Options unit tests. | ||
*/ | ||
class Erase_Deprecated_Flags_And_Options_Test extends WCPAY_UnitTestCase { | ||
|
||
/** | ||
* @var Erase_Deprecated_Flags_And_Options | ||
*/ | ||
private $migration; | ||
|
||
public function set_up() { | ||
$this->migration = new Erase_Deprecated_Flags_And_Options(); | ||
// one of the old options, for which we'll test for. | ||
update_option( '_wcpay_feature_grouped_settings', '1' ); | ||
// an unrelated option, that should not be deleted. | ||
update_option( '_wcpay__unrelated_option', 'fake-value' ); | ||
} | ||
|
||
public function tear_down() { | ||
delete_option( '_wcpay_feature_grouped_settings' ); | ||
delete_option( '_wcpay__unrelated_option' ); | ||
|
||
parent::tear_down(); | ||
} | ||
|
||
/** | ||
* @dataProvider versions_not_applying_migration_provider | ||
*/ | ||
public function test_it_does_nothing_if_migration_was_already_applied( string $stored_wcpay_version ) { | ||
$this->setup_environment( $stored_wcpay_version ); | ||
|
||
$this->migration->maybe_migrate(); | ||
|
||
// all options remains untouched. | ||
$this->assertEquals( '1', get_option( '_wcpay_feature_grouped_settings' ) ); | ||
$this->assertEquals( 'fake-value', get_option( '_wcpay__unrelated_option' ) ); | ||
} | ||
|
||
public function test_it_migrates_if_stored_woopayments_version_is_too_old() { | ||
$this->setup_environment( '8.0.0' ); | ||
|
||
$this->migration->maybe_migrate(); | ||
|
||
// this option has been deleted. | ||
$this->assertEquals( 'default-value', get_option( '_wcpay_feature_grouped_settings', 'default-value' ) ); | ||
// this option remains untouched. | ||
$this->assertEquals( 'fake-value', get_option( '_wcpay__unrelated_option' ) ); | ||
} | ||
|
||
private function setup_environment( $stored_wcpay_version ) { | ||
update_option( 'woocommerce_woocommerce_payments_version', $stored_wcpay_version ); | ||
} | ||
|
||
public function versions_not_applying_migration_provider() { | ||
return [ | ||
'newer major version' => [ '8.2.0' ], | ||
'newer minor version' => [ '8.1.1' ], | ||
'same version' => [ '8.1.0' ], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters