diff --git a/features/core-update.feature b/features/core-update.feature index a52bcd3b..f5cc14ab 100644 --- a/features/core-update.feature +++ b/features/core-update.feature @@ -167,7 +167,7 @@ Feature: Update WordPress core When I run `wp core update` Then STDOUT should contain: """ - WordPress is up to date + WordPress is up to date at version """ And STDOUT should not contain: """ @@ -384,3 +384,39 @@ Feature: Update WordPress core """ Success: """ + + @require-php-7.0 @require-wp-6.1 + Scenario: Attempting to downgrade without --force shows helpful message + Given a WP install + + When I run `wp core version` + Then save STDOUT as {WP_CURRENT_VERSION} + + When I try `wp core update --version=6.0` + Then STDOUT should contain: + """ + WordPress is up to date at version + """ + And STDOUT should contain: + """ + is older than the current version + """ + And STDOUT should contain: + """ + Use --force to update anyway + """ + And STDOUT should not contain: + """ + Success: + """ + And the return code should be 0 + + When I run `wp core update --version=6.0 --force` + Then STDOUT should contain: + """ + Updating to version 6.0 + """ + And STDOUT should contain: + """ + Success: WordPress updated successfully. + """ diff --git a/src/Core_Command.php b/src/Core_Command.php index b9bbb2b4..658a11e4 100644 --- a/src/Core_Command.php +++ b/src/Core_Command.php @@ -1269,8 +1269,14 @@ public function update( $args, $assoc_args ) { WP_CLI::success( 'WordPress updated successfully.' ); } + // Check if user attempted to downgrade without --force + } elseif ( ! empty( Utils\get_flag_value( $assoc_args, 'version' ) ) && version_compare( Utils\get_flag_value( $assoc_args, 'version' ), $wp_version, '<' ) ) { + // Requested version is older than current (downgrade attempt) + WP_CLI::log( "WordPress is up to date at version {$wp_version}." ); + WP_CLI::log( 'The version you requested (' . Utils\get_flag_value( $assoc_args, 'version' ) . ") is older than the current version ({$wp_version})." ); + WP_CLI::log( 'Use --force to update anyway (e.g., to downgrade to version ' . Utils\get_flag_value( $assoc_args, 'version' ) . ').' ); } else { - WP_CLI::success( 'WordPress is up to date.' ); + WP_CLI::success( "WordPress is up to date at version {$wp_version}." ); } }