From 17f8d5ae63564f87ac1157aa84c6acc4550ae2e0 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Fri, 12 Jun 2020 05:25:55 -0300 Subject: [PATCH 1/4] add clear template cache tool --- ...-rest-system-status-tools-v2-controller.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php b/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php index 325f551..41ad943 100644 --- a/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php +++ b/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php @@ -167,6 +167,15 @@ public function get_tools() { __( 'This tool will delete all customer session data from the database, including current carts and saved carts in the database.', 'woocommerce-rest-api' ) ), ), + 'clear_template_cache' => array( + 'name' => __( 'Clear template cache', 'woocommerce-rest-api' ), + 'button' => __( 'Clear', 'woocommerce-rest-api' ), + 'desc' => sprintf( + '%1$s %2$s', + __( 'Note:', 'woocommerce-rest-api' ), + __( 'This tool will empty the template cache.', 'woocommerce-rest-api' ) + ), + ), 'install_pages' => array( 'name' => __( 'Create default WooCommerce pages', 'woocommerce-rest-api' ), 'button' => __( 'Create pages', 'woocommerce-rest-api' ), @@ -206,6 +215,10 @@ public function get_tools() { unset( $tools['regenerate_thumbnails'] ); } + if ( ! function_exists( 'wc_clear_template_cache' ) ) { + unset( $tools['clear_template_cache'] ); + } + return apply_filters( 'woocommerce_debug_tools', $tools ); } @@ -538,6 +551,11 @@ public function execute_tool( $tool ) { $message = __( 'Database upgrade routine has been scheduled to run in the background.', 'woocommerce-rest-api' ); break; + case 'clear_template_cache': + wc_clear_template_cache(); + $message = __( 'Template cache cleared.', 'woocommerce-rest-api' ); + break; + default: $tools = $this->get_tools(); if ( isset( $tools[ $tool ]['callback'] ) ) { From 804784040e5c49303f46ae7ff8a2fafb96fb823e Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Mon, 15 Jun 2020 13:15:31 -0300 Subject: [PATCH 2/4] add cache clearing unsupported message --- .../class-wc-rest-system-status-tools-v2-controller.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php b/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php index 41ad943..af4d79b 100644 --- a/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php +++ b/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php @@ -552,8 +552,12 @@ public function execute_tool( $tool ) { break; case 'clear_template_cache': - wc_clear_template_cache(); - $message = __( 'Template cache cleared.', 'woocommerce-rest-api' ); + if ( function_exists( 'wc_clear_template_cache' ) ) { + wc_clear_template_cache(); + $message = __( 'Template cache cleared.', 'woocommerce-rest-api' ); + } else { + $message = __( 'The active version of WooCommerce does not support template cache clearing.', 'woocommerce-rest-api' ); + } break; default: From dbdc143769a30df1dc9338b7e1e2476310609c8a Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Mon, 15 Jun 2020 13:30:35 -0300 Subject: [PATCH 3/4] restore code accidentally removed in master merge --- .../class-wc-rest-system-status-tools-v2-controller.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php b/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php index 6403229..1ac8898 100644 --- a/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php +++ b/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php @@ -566,6 +566,9 @@ public function execute_tool( $tool ) { $message = __( 'Template cache cleared.', 'woocommerce-rest-api' ); } else { $message = __( 'The active version of WooCommerce does not support template cache clearing.', 'woocommerce-rest-api' ); + } + break; + case 'verify_db_tables': if ( ! method_exists( 'WC_Install', 'verify_base_tables' ) ) { $message = __( 'You need WooCommerce 4.2 or newer to run this tool.', 'woocommerce-rest-api' ); From f96321042a014cddb053ee243642a25b44302466 Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Mon, 15 Jun 2020 23:50:00 +0530 Subject: [PATCH 4/4] Unset flag to indidcate that tool did not ran. --- .../Version2/class-wc-rest-system-status-tools-v2-controller.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php b/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php index 1ac8898..a418b35 100644 --- a/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php +++ b/src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php @@ -566,6 +566,7 @@ public function execute_tool( $tool ) { $message = __( 'Template cache cleared.', 'woocommerce-rest-api' ); } else { $message = __( 'The active version of WooCommerce does not support template cache clearing.', 'woocommerce-rest-api' ); + $ran = false; } break;