Skip to content

Commit

Permalink
✨ Introduce additional cache purging
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosSynetos committed Sep 28, 2023
1 parent 8dabb3d commit be68080
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
28 changes: 21 additions & 7 deletions includes/class-wc-calypso-bridge-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package WC_Calypso_Bridge/Classes
* @since 1.0.0
* @version 2.2.15
* @version x.x.x
*/

use Automattic\WooCommerce\Admin\WCAdminHelper;
Expand Down Expand Up @@ -223,10 +223,10 @@ public function woocommerce_create_pages_callback() {

$this->write_to_log( $operation, 'INITIALIZED' );

// Set the operation as completed if the store is active for more than 10 minutes.
if ( WCAdminHelper::is_wc_admin_active_for( 10 * MINUTE_IN_SECONDS ) ) {
// Set the operation as completed if the store is active for more than 60 minutes.
if ( WCAdminHelper::is_wc_admin_active_for( 60 * MINUTE_IN_SECONDS ) ) {
update_option( $this->option_prefix . $operation, 'completed', 'no' );
$this->write_to_log( $operation, 'completed (10 minutes)' );
$this->write_to_log( $operation, 'completed (60 minutes)' );

return;
}
Expand Down Expand Up @@ -308,6 +308,13 @@ public function woocommerce_create_pages_callback() {
} else {
$this->write_to_log( $operation, 'failed to delete option woocommerce_' . $key . '_page_id : ' . $value );
}

$result_cache = wp_cache_delete( "woocommerce_{$key}_page_id", 'options' );
if ( $result_cache ) {
$this->write_to_log( $operation, 'deleted cache for option woocommerce_' . $key . '_page_id : ' . $value );
} else {
$this->write_to_log( $operation, 'failed to delete cache for option woocommerce_' . $key . '_page_id : ' . $value );
}
}

/*
Expand All @@ -330,6 +337,12 @@ public function woocommerce_create_pages_callback() {
wp_cache_flush();
usleep( 500000 );

$this->write_to_log( $operation, 'GETTING WOOCOMMERCE PAGE OPTIONS AFTER DELETION');
foreach ( $woocommerce_pages as $key => $page_slug ) {
$value = get_option( "woocommerce_{$key}_page_id" );
$this->write_to_log( $operation, 'getting option woocommerce_' . $key . '_page_id : ' . $value );
}

// Delete the following note, so it can be recreated with the correct refund page ID.
if ( class_exists( 'Automattic\WooCommerce\Admin\Notes\Notes' ) ) {
Automattic\WooCommerce\Admin\Notes\Notes::delete_notes_with_name( 'wc-refund-returns-page' );
Expand Down Expand Up @@ -689,7 +702,7 @@ private function write_to_log( $operation, $message ) {

/**
* Maybe delete page by slug.
* If the page is older than 10 minutes, it will be ignored.
* If the page is older than 60 minutes, it will be ignored.
*
* @since 2.2.15
*
Expand All @@ -714,13 +727,14 @@ private function maybe_delete_page_by_slug( $slug, $operation ) {
$current_time_gmt_ts = current_time( 'U', true );
$diff_ts = $current_time_gmt_ts - $page_gmt_ts;

if ( $diff_ts > 10 * MINUTE_IN_SECONDS ) {
$this->write_to_log( $operation, 'ignored page deletion ' . $slug . ' diff: ' . $diff_ts / 60 . ' minutes (older than 10 minutes) ' );
if ( $diff_ts > 60 * MINUTE_IN_SECONDS ) {
$this->write_to_log( $operation, 'ignored page deletion ' . $slug . ' diff: ' . $diff_ts / 60 . ' minutes (older than 60 minutes) ' );

return;
}

$result = wp_delete_post( $page['ID'], true );
clean_post_cache( $page['ID'] );
if ( $result ) {
$this->write_to_log( $operation, 'deleted page ' . $slug );
} else {
Expand Down
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ This section describes how to install the plugin and get it working.

== Changelog ==

= unreleased =
* Introduce additional cache purging while creating WooCommerce related pages #xxx
* Ensure existing WooCommerce related pages are deleted #xxx

= 2.2.15 =
* Revert all page deletion and delete only WooCommerce related pages #1304
* Purge cache before creating WooCommerce related pages #1304
Expand Down

0 comments on commit be68080

Please sign in to comment.