From be6808050a7274644ee98147a5cd08aa478eb9c5 Mon Sep 17 00:00:00 2001 From: "Panos (Panagiotis) Synetos" <2484390+PanosSynetos@users.noreply.github.com> Date: Thu, 28 Sep 2023 14:50:47 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Introduce=20additional=20cache=20pu?= =?UTF-8?q?rging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/class-wc-calypso-bridge-setup.php | 28 ++++++++++++++++------ readme.txt | 4 ++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/includes/class-wc-calypso-bridge-setup.php b/includes/class-wc-calypso-bridge-setup.php index d7004024..c04ddb4c 100644 --- a/includes/class-wc-calypso-bridge-setup.php +++ b/includes/class-wc-calypso-bridge-setup.php @@ -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; @@ -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; } @@ -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 ); + } } /* @@ -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' ); @@ -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 * @@ -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 { diff --git a/readme.txt b/readme.txt index 64896331..86df4cf4 100644 --- a/readme.txt +++ b/readme.txt @@ -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