From 44a3f2de21c4c2801e49ad945d0213b7f2549499 Mon Sep 17 00:00:00 2001 From: Jan Willem Oostendorp Date: Wed, 5 Apr 2023 14:11:31 +0200 Subject: [PATCH 1/3] When flushing cache on a multisite give a warning. Cache flushes on all sites, not just the current url. --- features/cache.feature | 14 ++++++++++++++ src/Cache_Command.php | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/features/cache.feature b/features/cache.feature index 472f28d19..453c0ce1b 100644 --- a/features/cache.feature +++ b/features/cache.feature @@ -132,3 +132,17 @@ Feature: Managed the WordPress object cache """ Error: Could not replace object 'bar' in group 'foo'. Does it not exist? """ + Scenario: Flushing cache on a multisite installation + Given a WP multisite installation + + When I try `wp cache flush` + Then STDERR should not contain: + """ + Warning: You are using a multisite installation. Flushing the cache will flush the cache for all sites. + """ + + When I try `wp cache flush --url=example.com` + Then STDERR should contain: + """ + Warning: You are using a multisite installation. Flushing the cache will flush the cache for all sites. + """ diff --git a/src/Cache_Command.php b/src/Cache_Command.php index 1b5c8b172..852a1baa9 100644 --- a/src/Cache_Command.php +++ b/src/Cache_Command.php @@ -155,8 +155,12 @@ public function delete( $args, $assoc_args ) { * Success: The cache was flushed. */ public function flush( $args, $assoc_args ) { - $value = wp_cache_flush(); + if ( WP_CLI::has_config( 'url' ) && ! empty( WP_CLI::get_config()['url'] ) && is_multisite() ) { + WP_CLI::warning( 'You are using a multisite installation. Flushing the cache will flush the cache for all sites.' ); + } + + $value = wp_cache_flush(); if ( false === $value ) { WP_CLI::error( 'The object cache could not be flushed.' ); } From ca47a555ced4fe56c29b4c36d455af5383e8949f Mon Sep 17 00:00:00 2001 From: Jan Willem Oostendorp Date: Wed, 5 Apr 2023 17:22:31 +0200 Subject: [PATCH 2/3] Updated the --url warning. --- features/cache.feature | 4 ++-- src/Cache_Command.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/features/cache.feature b/features/cache.feature index 453c0ce1b..5b4369434 100644 --- a/features/cache.feature +++ b/features/cache.feature @@ -138,11 +138,11 @@ Feature: Managed the WordPress object cache When I try `wp cache flush` Then STDERR should not contain: """ - Warning: You are using a multisite installation. Flushing the cache will flush the cache for all sites. + Warning: Ignoring the --url= argument, because flushing the cache affects all sites on a multisite installation. """ When I try `wp cache flush --url=example.com` Then STDERR should contain: """ - Warning: You are using a multisite installation. Flushing the cache will flush the cache for all sites. + Warning: Ignoring the --url= argument, because flushing the cache affects all sites on a multisite installation. """ diff --git a/src/Cache_Command.php b/src/Cache_Command.php index 852a1baa9..5a72a4b40 100644 --- a/src/Cache_Command.php +++ b/src/Cache_Command.php @@ -157,7 +157,7 @@ public function delete( $args, $assoc_args ) { public function flush( $args, $assoc_args ) { if ( WP_CLI::has_config( 'url' ) && ! empty( WP_CLI::get_config()['url'] ) && is_multisite() ) { - WP_CLI::warning( 'You are using a multisite installation. Flushing the cache will flush the cache for all sites.' ); + WP_CLI::warning( 'Ignoring the --url= argument, because flushing the cache affects all sites on a multisite installation.' ); } $value = wp_cache_flush(); From d6f3fd7762577caa619ac43940b83df6e7f30f3b Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Wed, 5 Apr 2023 16:59:48 -0700 Subject: [PATCH 3/3] Remove comma from the message --- features/cache.feature | 5 +++-- src/Cache_Command.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/features/cache.feature b/features/cache.feature index 5b4369434..941698de3 100644 --- a/features/cache.feature +++ b/features/cache.feature @@ -132,17 +132,18 @@ Feature: Managed the WordPress object cache """ Error: Could not replace object 'bar' in group 'foo'. Does it not exist? """ + Scenario: Flushing cache on a multisite installation Given a WP multisite installation When I try `wp cache flush` Then STDERR should not contain: """ - Warning: Ignoring the --url= argument, because flushing the cache affects all sites on a multisite installation. + Warning: Ignoring the --url= argument because flushing the cache affects all sites on a multisite installation. """ When I try `wp cache flush --url=example.com` Then STDERR should contain: """ - Warning: Ignoring the --url= argument, because flushing the cache affects all sites on a multisite installation. + Warning: Ignoring the --url= argument because flushing the cache affects all sites on a multisite installation. """ diff --git a/src/Cache_Command.php b/src/Cache_Command.php index 5a72a4b40..fd2d0c57e 100644 --- a/src/Cache_Command.php +++ b/src/Cache_Command.php @@ -157,7 +157,7 @@ public function delete( $args, $assoc_args ) { public function flush( $args, $assoc_args ) { if ( WP_CLI::has_config( 'url' ) && ! empty( WP_CLI::get_config()['url'] ) && is_multisite() ) { - WP_CLI::warning( 'Ignoring the --url= argument, because flushing the cache affects all sites on a multisite installation.' ); + WP_CLI::warning( 'Ignoring the --url= argument because flushing the cache affects all sites on a multisite installation.' ); } $value = wp_cache_flush();