Skip to content

Commit

Permalink
Also fix archiving a site by numeric slug (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber authored Nov 16, 2023
1 parent 3f7c916 commit ce37f3c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
28 changes: 27 additions & 1 deletion features/site.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/Site_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ce37f3c

Please sign in to comment.