Cleanup caching data on plugin upgrade

This commit is contained in:
Emili Castells Guasch 2023-03-21 12:22:53 +01:00
parent 99c5351689
commit f857315055
3 changed files with 23 additions and 4 deletions

View file

@ -102,11 +102,11 @@ class DCCProductStatus {
return (bool) $this->cache->get( self::DCC_STATUS_CACHE_KEY );
}
if ( is_bool( $this->current_status_cache ) ) {
if ( $this->current_status_cache === true ) {
return $this->current_status_cache;
}
if ( $this->settings->has( 'products_dcc_enabled' ) && $this->settings->get( 'products_dcc_enabled' ) ) {
if ( $this->settings->has( 'products_dcc_enabled' ) && $this->settings->get( 'products_dcc_enabled' ) === true ) {
$this->current_status_cache = true;
return true;
}

View file

@ -91,10 +91,10 @@ class PayUponInvoiceProductStatus {
return (bool) $this->cache->get( self::PUI_STATUS_CACHE_KEY );
}
if ( is_bool( $this->current_status_cache ) ) {
if ( $this->current_status_cache === true ) {
return $this->current_status_cache;
}
if ( $this->settings->has( 'products_pui_enabled' ) && $this->settings->get( 'products_pui_enabled' ) ) {
if ( $this->settings->has( 'products_pui_enabled' ) && $this->settings->get( 'products_pui_enabled' ) === true ) {
$this->current_status_cache = true;
return true;
}

View file

@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway;
use Psr\Log\LoggerInterface;
use Throwable;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
use WC_Order;
@ -261,6 +262,24 @@ class WCGatewayModule implements ModuleInterface {
}
);
add_action(
'woocommerce_paypal_payments_gateway_migrate_on_update',
static function() use ( $c ) {
$dcc_status_cache = $c->get( 'dcc.status-cache' );
assert( $dcc_status_cache instanceof Cache );
$pui_status_cache = $c->get( 'pui.status-cache' );
assert( $pui_status_cache instanceof Cache );
$dcc_status_cache->delete( DCCProductStatus::DCC_STATUS_CACHE_KEY );
$pui_status_cache->delete( PayUponInvoiceProductStatus::PUI_STATUS_CACHE_KEY );
$settings = $c->get( 'wcgateway.settings' );
$settings->set( 'products_dcc_enabled', false );
$settings->set( 'products_pui_enabled', false );
$settings->persist();
}
);
add_action(
'wp_loaded',
function () use ( $c ) {