From ce37f3c045628ee583b878a5abddda23922cb617 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 16 Nov 2023 05:25:22 -0800 Subject: [PATCH] Also fix archiving a site by numeric slug (#448) --- features/site.feature | 28 +++++++++++++++++++++++++++- src/Site_Command.php | 8 ++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/features/site.feature b/features/site.feature index c27b9b34..2d44f286 100644 --- a/features/site.feature +++ b/features/site.feature @@ -139,7 +139,33 @@ Feature: Manage sites in a multisite installation When I try the previous command again Then STDERR should contain: """ - Site with slug '42' does not exist. + Error: Could not find site with slug '42'. + """ + And the return code should be 1 + + Scenario: Archive a site by a numeric slug + Given a WP multisite install + + When I run `wp site create --slug=42` + Then STDOUT should contain: + """ + Success: Site 2 created: http + """ + And STDOUT should contain: + """ + ://example.com/42/ + """ + + When I run `wp site archive --slug=42` + Then STDOUT should contain: + """ + Success: Site 2 archived. + """ + + When I try `wp site archive --slug=43` + Then STDERR should contain: + """ + Error: Could not find site with slug '43'. """ And the return code should be 1 diff --git a/src/Site_Command.php b/src/Site_Command.php index b06a7909..4379b7a2 100644 --- a/src/Site_Command.php +++ b/src/Site_Command.php @@ -334,7 +334,7 @@ public function delete( $args, $assoc_args ) { if ( isset( $assoc_args['slug'] ) ) { $blog_id = get_id_from_blogname( $assoc_args['slug'] ); if ( null === $blog_id ) { - WP_CLI::error( "Site with slug '{$assoc_args['slug']}' does not exist." ); + WP_CLI::error( sprintf( 'Could not find site with slug \'%s\'.', $assoc_args['slug'] ) ); } $blog = get_blog_details( $blog_id ); } else { @@ -982,11 +982,11 @@ private function get_sites_ids( $args, $assoc_args ) { $slug = Utils\get_flag_value( $assoc_args, 'slug', false ); if ( $slug ) { - $blog = get_blog_details( trim( $slug, '/' ) ); - if ( ! $blog ) { + $blog_id = get_id_from_blogname( trim( $slug, '/' ) ); + if ( null === $blog_id ) { WP_CLI::error( sprintf( 'Could not find site with slug \'%s\'.', $slug ) ); } - return [ $blog->blog_id ]; + return [ $blog_id ]; } return $args;