From d0de964eaae03400d7476b6ecd1d16fb3a4ec689 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Wed, 30 Aug 2023 15:19:23 +0200 Subject: [PATCH 1/2] Update to wp-cli-tests v4 (which requires WPCS v3) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b5294858..4620c372 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ }, "require-dev": { "wp-cli/entity-command": "^1.3 || ^2", - "wp-cli/wp-cli-tests": "^3.1" + "wp-cli/wp-cli-tests": "^4" }, "config": { "process-timeout": 7200, From 7e341e35de88cd96a03e7eb94870804a7d836fcd Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Wed, 30 Aug 2023 15:24:56 +0200 Subject: [PATCH 2/2] Fix all autofixable CS issues --- cache-command.php | 2 +- src/Cache_Command.php | 1 - src/Transient_Command.php | 60 ++++++++++++++++++--------------------- 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/cache-command.php b/cache-command.php index 1b7bfb25..338e0221 100644 --- a/cache-command.php +++ b/cache-command.php @@ -4,7 +4,7 @@ return; } -$wpcli_cache_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php'; +$wpcli_cache_autoloader = __DIR__ . '/vendor/autoload.php'; if ( file_exists( $wpcli_cache_autoloader ) ) { require_once $wpcli_cache_autoloader; } diff --git a/src/Cache_Command.php b/src/Cache_Command.php index 9071cf34..b25ba1d7 100644 --- a/src/Cache_Command.php +++ b/src/Cache_Command.php @@ -406,5 +406,4 @@ public function flush_group( $args, $assoc_args ) { } WP_CLI::success( "Cache group '$group' was flushed." ); } - } diff --git a/src/Transient_Command.php b/src/Transient_Command.php index 2d694550..cbff5b1c 100644 --- a/src/Transient_Command.php +++ b/src/Transient_Command.php @@ -466,8 +466,7 @@ private function delete_expired( $network ) { time() ) ); - } else { - if ( ! is_multisite() ) { + } elseif ( ! is_multisite() ) { // Non-Multisite stores site transients in the options table. $count += $wpdb->query( $wpdb->prepare( @@ -481,21 +480,20 @@ private function delete_expired( $network ) { time() ) ); - } else { - // Multisite stores site transients in the sitemeta table. - $count += $wpdb->query( - $wpdb->prepare( - "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b + } else { + // Multisite stores site transients in the sitemeta table. + $count += $wpdb->query( + $wpdb->prepare( + "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b WHERE a.meta_key LIKE %s AND a.meta_key NOT LIKE %s AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) ) AND b.meta_value < %d", - Utils\esc_like( '_site_transient_' ) . '%', - Utils\esc_like( '_site_transient_timeout_' ) . '%', - time() - ) - ); - } + Utils\esc_like( '_site_transient_' ) . '%', + Utils\esc_like( '_site_transient_timeout_' ) . '%', + time() + ) + ); } // The above queries delete the transient and the transient timeout @@ -553,8 +551,7 @@ private function delete_all( $network ) { Utils\esc_like( '_transient_' ) . '%' ) ); - } else { - if ( ! is_multisite() ) { + } elseif ( ! is_multisite() ) { // Non-Multisite stores site transients in the options table. $deleted = $wpdb->query( $wpdb->prepare( @@ -575,28 +572,27 @@ private function delete_all( $network ) { Utils\esc_like( '_site_transient_' ) . '%' ) ); - } else { - // Multisite stores site transients in the sitemeta table. - $deleted = $wpdb->query( - $wpdb->prepare( - "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b + } else { + // Multisite stores site transients in the sitemeta table. + $deleted = $wpdb->query( + $wpdb->prepare( + "DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b WHERE a.meta_key LIKE %s AND a.meta_key NOT LIKE %s AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )", - Utils\esc_like( '_site_transient_' ) . '%', - Utils\esc_like( '_site_transient_timeout_' ) . '%' - ) - ); + Utils\esc_like( '_site_transient_' ) . '%', + Utils\esc_like( '_site_transient_timeout_' ) . '%' + ) + ); - $count += $deleted / 2; // Ignore affected rows for timeouts. + $count += $deleted / 2; // Ignore affected rows for timeouts. - $count += $wpdb->query( - $wpdb->prepare( - "DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE %s", - Utils\esc_like( '_site_transient_' ) . '%' - ) - ); - } + $count += $wpdb->query( + $wpdb->prepare( + "DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE %s", + Utils\esc_like( '_site_transient_' ) . '%' + ) + ); } if ( $count > 0 ) {