Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion features/core-update.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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.
"""
8 changes: 7 additions & 1 deletion src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}." );
}
}

Expand Down
Loading